Localizing for sub-cultures on WP7 not getting picked up
I am trying to localize my wp7 application and I need to have different strings for de-DE
and de-AT
because there are some language differences between those two cultures even though the basic settings are the same.
I did the following to achieve this:
- Created an
AppResources.resx
file for the default English text - Created an
AppResources.de-DE.resx
file for the German text - Created an
AppResources.de-AT.resx
file for the German text for Austrian sub culture - in the Assembly Information... in the project properties I set English as my Neutral Language
- I closed the solution, opened up my
project.csproj
file and changed the<SupportedCultures/>
to the following:<SupportedCultures>de-AT;de-DE</SupportedCultures>
- I added a new Class
LocalizedStrings
, 开发者_Go百科registered it in Application.Resources in App.xaml and changed the output string accordingly.
Both the Emulator as the handset are set to Austrian Locale, System.Globalization.CultureInfo.CurrentCulture.ToString();
returns de-AT, but regardless of that the texts defined in AppResources.de-DE.resx
are used and not the ones defined in the file for the Austrian culture.
Any idea how I might solve this issue?
You should check the CultureInfo.CurrentUICulture, not the CurrentCulture!
That is the property that controls what resources get loaded for interface!
The value of CurrentUICulture should match the one selected in the phone/emulator Settings -> Region+Language -> Display Language.
Ideally, you can always override the system imposed CurrentUICulture by setting a different CultureInfo on Thread.CurrentUICulture.
精彩评论