ResourceLoader and Neutral Language - c#

I want to localize my Windows Store app. I have string\cs-CZ\Resources.resw and I load the strings in C# using ResourceLoader. When I have my system set to cs-CZ locale, the string are returned ok. When I set to to another locale, the GetString method returns an empty string. I have my projects neutral solution set to cs-CZ so what is the problem? How do I make the app always take resources from string\cs-CZ\Resources.resw?

The default locale can be programatically set using
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "cs-CZ";
in OnLaunched

Related

Windows Forms Localize resx without changing Culture

I know it's easy to localize Windows Forms App: set Localizable=True, change Language and set text in Controls for every Language. This information saves in resx-files and application will automatically select the required file. Great!
I know about disadvantages of this solution (you need to rebuild the app if there a typo, it's impossible to change language in runtime, etc), but it's not a problem for me and "resources" is the simpliest, built-in solution.
But this mechanism uses the property Culture of app's thread.
My app is the part ("plugin") of the bigger application and works in the same Thread.
The main application is multilingual too, but it doesn't use Culture to change interface's language. I can change the thread's culture globally, but it crushes the main app's interface.
So my question:
is it possible to manually set the resx-localizable resurce file that will be used? Not based on Culture, but, for example, on some variable in my app:
if (this.Language == "fr")
this.Resources.Add("Form1.fr.resx");
else
this.Resources.Add("Form1.en.resx");
Or something else.
Thank you!
My sandbox:
https://github.com/Tereami/WindowsFormsTestLanguage
The built resources file has a property ResourceManager that's used to return the desired content. This has an overload with a CultureInfo parameter. You can use it to request resources in individual languages:
var desiredCulture = new CultureInfo("en-us");
var text = MyStrings.ResourceManager.GetString(nameof(Resources.ExitMessage), desiredCulture);
If you want to set the culture globally for your resource file, you could also set it through the corresponding property:
var desiredCulture = new CultureInfo("en-us");
MyStrings.Culture = desiredCulture;
var text = MyStrings.ExitMessage;

Why C# CultureInfo.CurrentCulture give en_US in Window-7 Japanese culture?

I have window-7 Ultimate OS.I written below code for get current culture info.
void TestMessage()
{
CultureInfo culture = CultureInfo.CurrentCulture;
CultureInfo culture1 = Thread.CurrentThread.CurrentCulture;
}
it is working fine with window-8,server 2012 Japanese OS. But it is not working in window-7 only. Please look below image of my computer region setting
Can any anyone guide me to get correct culture name?
Thanks,
There's CurrentCulture and CurrentUICulture.
CurrentCulture: formatting of data (numbers, dates), it is configured in Windows using the tab visible in your screenshot
CurrentUICulture: the language to speak/write to your user, it is configured in Windows using one of the other tabs showing in your screenshot. ("Keyboard & Languages" I think)
Your screenshot:
... is showing american numeric notation because CurrentCulture is set to en-US
... is talking Japanese because CurrentUICulture is very likely set to Japanese
So, if you need to know what language to use for localization, as is probably your case, you should be using CurrentUICulture.

Resources Culture issue in Silverlight 5

Sorry, in advance for my English, its my first post here.
I've got strange problem with RESX, supported culture in Silverlight.
Its silverlight app with 1 web(asp.net) project which start whole silverlight app, 1 main project(silverlight, sl.Application) and others which are use as modules(silverlight) in main project (solution explorer screen: http://i.imgur.com/A4sHWRI.png?1 ). Sl.Application can invoke other projects and use theirs views as part of the main view placed in sl.application
I tried to add different cultures, so:
I add to my app Supported cultures EN and CS to each cs.proj.
<SupportedCultures>pl;en;cs;de;ru;cz;sk</SupportedCultures>
My Neutral culture is set to PL in assemby info in each project.
[assembly: NeutralResourcesLanguageAttribute("pl-PL")]
Create resx Files for different cultures, here fol PL, EN , CS: http://i.imgur.com/P6woiV2.png
At starting app you can choose which culture you want, by clicking on specific flag.
First lets start with PL - its neutral culture, so i dont have to change anything. Using
var culture = System.Threading.Thread.CurrentThread.CurrentUICulture;
var test_en = Resources.DrivesBook.ResourceManager.GetString("AdresArrival", culture);
I checked that culture is set to PL and resource (DriveBook.resx) return correct string in PL
Next:
Let's try EN, Start App, choose EN flag - change culture to en-GB.
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-GB");
Using same code as above, returns me EN string so its still good
The best begins when i tried to use CS.
Same as above, I choose CS flag - change culture to cs-CZ
Using in SL.Application
var culture = System.Threading.Thread.CurrentThread.CurrentUICulture;
its returns me cs-CZ culture so I thought that there will be ok, when I call
var test_cs = Resources.DrivesBook.ResourceManager.GetString("AdresArrival", culture);
it returns me string from CS culture, still all works fine, so where is the problem?
When i tried same in others projects (from Common or Modules folder), here comes magic :)
Same as above
Using in Modules.Auxiliary
var culture = System.Threading.Thread.CurrentThread.CurrentUICulture;
still OK, we got cs-CZ culture, seems to works fine, but
var test_cs = Resources.DrivesBook.ResourceManager.GetString("AdresArrival", culture);
it returns me string from PL culture, not from CS
Summation:
Changing culture works fine, for EN, whole app got EN string from resx files, but when I change to CS, only SL.Application can resolve *.cs.resx file, other projects looks like they have not seen *.cs.resx files. While adding En and CS I d exactly same work for both and EN work fine, but CS not. its there any posibily that there is some property in cs.proj that limit max supported cultures in current project, or do you have any idea what I did wrong?
ok, I solved it by myself
Problem was in my custom framework, which was responsible for differential loading resources. Resolving dll only via filename, not included filePath (here folder cs, en for different cultures) caused overwrite files depending on the lexical order, so CS.resx was loaded firstly, but later I load EN resource and overwrite cs.resx. This framework starts working when comes to loading main xap. Main sl project works, cuz it was loaded earlier, e.g. for loading screen so resource.cs.resx was loaded when my framework couldn't corrupt it

Internationalize Windows Phone 7 App

I am currently working on a windows phone application that takes some information from the user and returns some other information based on the user input.
The application works great if the specific device has its region settings set to US. If the region settings of the device are set to Greek or German, some problems occur. For example, the US decimal point character "." is considered as "," and vice versa. As a result, all the calculations are false.
What I want to do is internationalize the application so that it works exactly the same no matter what the regional settings are. Is this possible?
If you want your app allways to show number and dates in one specify format you can force the app to allways run in one specify culture like this.
You just have to set the current thread of your app to one specify culture (add to the App.cs file)!
public App()
{
// Standard Silverlight initialization
InitializeComponent();
// Phone-specific initialization
InitializePhoneApplication();
// Set the current thread to US!
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

Mysterious Resources /CultureInfo behaviour in WPF App

i have two Resources files in the Properties folder of a WPF-project (VS 2008):
Resources.resx
Resources.de-DE.resx
Selecting the culture "de-DE" does not work (no error, but always the strings from "Resources.resx" are used):
public App()
{
UntitledProject2.Properties.Resources.Culture = new CultureInfo("de-DE");
}
BUT: if I rename "Resources.de-DE.resx" to "Resources.fr-CA.resx" or "Resources.en-US.resx"
and then set it via
UntitledProject2.Properties.Resources.Culture = new CultureInfo("fr-CA");
it works!! But why!? Mysterious...
By default, WPF will always use "en-US"; at least it did the last time I checked (which was .net 3.5). If you want WPF to instead use the culture currently set by the system, you would execute this code block:
FrameworkElement.LanguageProperty.OverrideMetadata(
typeof(FrameworkElement),
new FrameworkPropertyMetadata(
XmlLanguage.GetLanguage(
CultureInfo.CurrentCulture.IetfLanguageTag)));
This will override the default value used for the FrameworkElement's Language dependency property, which, again, is "en-US" by default.
Execute this code once and early on in the lifetime of your application. AFter that, you shouldn't have to worry about it again, unless you expect your user to be switching the culture in the middle of program execution...

Categories

Resources