ResourceManager.GetString gives localization with wrong encoding

1k views Asked by At

I use ResourceManager to localize strings in my web forms application. The application supports en-us and sv-se. The strings are fetched correctly from the respective resource files, but when they are displayed, unicode characters come as junk values.

resources.sv-se.restext

...
ContactInfoFormatPrimary={0} (primär)
...

Output

enter image description here

Code that gets the resource:

ResourceManager resourceManager  = GetResourceManager(...)
...
text = resourceManager.GetString(resourceId);

I tried debugging the code, and the text returned is {0} (prim�r)

What is causing the resource to decode incorrectly?

UPDATE:

I was able to use the same architecture in a console app and obtain the correct string, is there anything related to application configuration that i need to take care of?

1

There are 1 answers

1
Good Night Nerd Pride On BEST ANSWER

Most likely you are not saving your resource text files (.txt, .restext) as UTF-8 or UTF-16/Unicode. See the following paragraph from the MSDN documentation of Resgen.exe:

A text file that contains resources must be saved with UTF-8 or Unicode (UTF-16) encoding unless it contains only characters in the Basic Latin range (to U+007F). Resgen.exe removes extended ANSI characters when it processes a text file that is saved using ANSI encoding.

The easiest way to check the enconding of a text file is to open it in Notepad, click Save as... in the File menu and check what's displayed in the Encoding drop down in the lower right corner. It should be set to UTF-8 or Unicode.

To fix the encoding just select UTF-8 or Unicode in the Save as... dialog of Notepad and hit Save overwriting the original file.