chrisva
chrisva

Reputation: 655

Windows 8 Metro app (XAML) - How to set a default startup language?

I try to set a default startup language in my Windows Metro app in App.xaml.cs, but I cannot find the place to do it. Usually I set this up using Thread.CurrentCulture in C#, but I cannot locate the Thread namespace. Anything I am missing here?

Upvotes: 3

Views: 6213

Answers (7)

Stanislav Iegorov
Stanislav Iegorov

Reputation: 91

If it's still on demand I have an option here:

Try set up default App language in Package.appxmanifest. Open the manifest with VS and set default language in appropriate box (application UI -> default language).

Hope it helps.

Upvotes: 1

user2498562
user2498562

Reputation: 1

Open the code view of your Package.appxmanifest Change Resources to:

  <Resources>
    <Resource Language="x-generate" />
  </Resources>

Upvotes: 0

Erik
Erik

Reputation: 1

I think what you're looking for (in the CP) is Windows.Globalization.ApplicationPreferences.PreferredLanguage.

Note that your manifest should list all of the languages you actually support. VS will set the languages for you automatically if the manifest in the project contains x-generate.

Upvotes: 0

Krzysztof Kaczor
Krzysztof Kaczor

Reputation: 5588

This works great in Windows8 CP:

Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "de";
var resourceLoader = new ResourceLoader();

Upvotes: 4

klagodzic
klagodzic

Reputation: 1

Maybe setting it in App.xaml.cs like shown below will help

Windows.Globalization.ApplicationPreferences.PreferredLanguage = "no";

Where "no" is BCP47 language tag for norwegian language.

Update: Metro app language change at runtime

According to Windows 8 SDK sample "Application resources and localization"

It is possible that, while an application is running, the language, scale, contrast or other settings may change. In order to handle these events, event listeners should be registered to listen for and react to the change. This can be done either by storing state and refreshing the page or by redrawing specific resources.

Now in my language change selection event i'm setting the PreferredLanguage like:

Windows.Globalization.ApplicationPreferences.PreferredLanguage = "en";
this.Frame.Navigate(this.GetType());

And the key thing i've been missing is code below in App's OnLaunched event:

ResourceManager.Current.DefaultContext.QualifierValues.MapChanged += async (s, m) => 
{
    if (m.Key == "Language")
    {
        // react to language change
    }
};

I didn't place this event registration in Page's construtor or any page's event (as it is in SDK sample) because then it could've been registered multiple times. Still this event has to be registered somewhere for language change to take effect at runtime.

Upvotes: 0

Yasser Makram
Yasser Makram

Reputation: 206

You can set the Default thread culture using CultureInfo.DefaultThreadCurrentCulture property.

Upvotes: 0

Tomas Jansson
Tomas Jansson

Reputation: 23462

You could try to set it on the project assembly. Try right click the project, then "Assembly Information..." and select your neutral culture.

Upvotes: 0

Related Questions