开发者

Silverlight localization bug?

开发者 https://www.devze.com 2023-01-30 01:46 出处:网络
I have a very weird problem, which looks like it could be a Silverlight bug. I have reproduced this in a simple application created from VS2010, Silverlight Application project default template.

I have a very weird problem, which looks like it could be a Silverlight bug. I have reproduced this in a simple application created from VS2010, Silverlight Application project default template.

In the app I have two .resx files, "Strings.resx" and "Strings.de.resx". They each have one key "SomeString", like so:

Strings.resx - SomeString - "some test string"

Strings.de.resx - SomeString - "some DE test string"

On the single application MainPage.xaml I just slapped a TextBlock, which I use in code like so, in the Main开发者_如何学PythonPage's class constructor:

   Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo("de-DE");
   txt.Text = Strings.SomeString;

   Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
   txt.Text = Strings.SomeString;

Stepping through this with the debugger shows txt.Text to be "some DE test string" first and then "some test string". So everything works as it should.

HOWEVER, i installed the German language pack on my machine. Now, if I change, in the machine's Regional Settings, the system language to "Deutsch" and logoff/logon for the changes to take effect, the same code works differently: the SAME string "some DE test string" is retrieved from the resources TWICE. Basically, the second setting of the current culture/uiculture to "en-US" does nothing and the German string is still retrieved.

So in effect, if I want to have an app where the user can change the display language independently of the system launguage, I can't do it, because the incorrect resources are retrieved.

Again, in the case when the Windows OS Language is set to English, everything works correctly, I can change the culture and it works, correct string resources are loaded. When the Windows OS Language is set to Deutsch (haven't checked for others) I am unable to load the english string resources.

The problem manifests itself on both Vista and Windows 7 machines, haven't tested on others.

ps: the csproj file is changed to have <SupportedCultures>en,en-US,de,de-DE</SupportedCultures>

Any idea what I'm doing wrong?


I think your issue comes from the default culture of your silverlight assembly: Did you recompile the App after having changed Windows culture from en to de?

Try to check the assembly neutral culture, and set is manually:

[assembly: NeutralResourcesLanguage("en")]

in the assemblyInfo.cs file


I just had the same problem. What fixed it for me, is that I didn't rely on Silverlight guessing the correct neutral language. My app translates to en, de, fr and it. So i did (in every project I have localizable strings):

GuiStrings.resx
GuiStrings.en.resx
GuiStrings.de.resx
GuiStrings.fr.resx
GuiStrings.it.resx

This fixes the weird issue, that Silverlight ignores the neutral language ('en') on german machines.

0

精彩评论

暂无评论...
验证码 换一张
取 消