Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.resx file same key with different case

I am trying to localize my app and according to https://learn.microsoft.com/en-us/aspnet/core/fundamentals/localization. I am using English phrases as my keys and French translation as my value. Unfortunately, I have quite a few keys that are the same but that differ in case (i.e., "Hello World" and "HELLO WORLD").

The .resx designer will not allow you to enter the two keys, but if I edit it in text mode, my app builds, and the resources get embedded. However, one, of the "Hello World"'s is missing.

Is there a way to do this, and if not, is there a workaround?

like image 905
Grant Parker Avatar asked Jul 26 '26 05:07

Grant Parker


1 Answers

It's mentioned in that "About Title" example of the tutorial that:

Alternatively, you can use the traditional approach and provide a key to retrieve the default language string.

So an option is to use resource keys instead of the actual strings (see section on Working with resource files). Then when you add the string keys to the resources, as noted in this Naming Resources guidelines, use Pascal Casing instead for your resource keys.

This means:

  • No spaces
  • No keys that differ only in case

Taking your example of "Hello World" and "HELLO WORLD", you can differentiate them by adding a prefix/suffix identifier, like this:

HelloWorldDnCase
HelloWorldUpCase

But, if you still want to use the actual strings as the key (similar to the "About Title") example, you could just use a single key, "Hello World", then just programmatically upcase the wording when you need it to be displayed in all-uppercase.

like image 150
Gino Mempin Avatar answered Jul 28 '26 08:07

Gino Mempin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!