Jānis Riekstiņš
Jānis Riekstiņš

Reputation: 1

C# changing application language programmatically (User prefference)

I need a few tips on how to change application launguage. (Windows 8.1)

So here is my code that I put under OnLaunched method, It gets the current preffered launguage. I am using Multilingual app toolkit. I have all the resource files.

But I have no idea what to do next.

var rootFrame1 = new Frame(); rootFrame1.Language = Windows.System.UserProfile.GlobalizationPreferences.Languages[0];

Upvotes: 0

Views: 1357

Answers (2)

user1635881
user1635881

Reputation: 239

Some resources point to placing this code in Page constructor to react to your default language being changed

ResourceContext.GetForCurrentView().QualifierValues.MapChanged +=
                (IObservableMap<string, string> sender, IMapChangedEventArgs<string> e) =>
                {
                    ResourceManager.Current.DefaultContext.Reset();
                };

Also, worth mentionig is that preferable method for changing language is setting Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride property.

This works not so good for Windows Phone 8.1, but some claim that this solved their issue on Windows 8.1.

Upvotes: 0

fillobotto
fillobotto

Reputation: 3775

You have to set current CultureInfo properties in this way:

var culture = new CultureInfo("en-US"); 
Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = culture.Name; 
CultureInfo.DefaultThreadCurrentCulture = culture; 
CultureInfo.DefaultThreadCurrentUICulture = culture; 

Upvotes: 4

Related Questions