locked
[UWP]Is there any way to programmatically set UI culture on app start? RRS feed

  • Question

  • The official sample ApplicationResources on github suggests change system UI language to test different languages via the system Settings applet. It's not as convenient as what I expected. Is it possible to set app's UI culture uisng code in App.xaml.cs, for example in OnLaunched or even in the ctor?

    Ignorance is blissful

    Monday, July 10, 2017 12:22 PM

Answers

  • The official sample ApplicationResources on github suggests change system UI language to test different languages via the system Settings applet. It's not as convenient as what I expected. Is it possible to set app's UI culture uisng code in App.xaml.cs, for example in OnLaunched or even in the ctor?

    Ignorance is blissful

    Hi Neo, I uses the following API for localization test:

    #if DEBUG && LOC
                ApplicationLanguages.PrimaryLanguageOverride = "zh-cn";
    #endif



    I build UWPs: Arrnage Pro, Cloud Resource Tools

    • Marked as answer by Neo the 1 Tuesday, July 11, 2017 1:51 AM
    Monday, July 10, 2017 6:06 PM

All replies

  • The official sample ApplicationResources on github suggests change system UI language to test different languages via the system Settings applet. It's not as convenient as what I expected. Is it possible to set app's UI culture uisng code in App.xaml.cs, for example in OnLaunched or even in the ctor?

    Ignorance is blissful

    Hi Neo, I uses the following API for localization test:

    #if DEBUG && LOC
                ApplicationLanguages.PrimaryLanguageOverride = "zh-cn";
    #endif



    I build UWPs: Arrnage Pro, Cloud Resource Tools

    • Marked as answer by Neo the 1 Tuesday, July 11, 2017 1:51 AM
    Monday, July 10, 2017 6:06 PM
  • Great! This works, except one small thing - it seems it has no effect on the appxmanifest Display Name if Display Name is localized using ms-resource scheme.

    I have a small test project, I set override language in App class ctor:

    ApplicationLanguages.PrimaryLanguageOverride = "en-US";

    All text in the root frame changes to English as expected, except the app's window title which remains Chinese. Is there any way to change this also?


    Ignorance is blissful



    • Edited by Neo the 1 Monday, July 10, 2017 9:35 PM
    Monday, July 10, 2017 9:32 PM
  • Hey there,

    I did the same as to put it 1st line in constructor of the App and it worked for me:

            public App()
            {
                ApplicationLanguages.PrimaryLanguageOverride = "zh-cn";
                // balabala ...
            }

    Could you please double check the package settings and making sure the proper resource does exist:

    Display name in Package.appxmanifest: ms-resource:AppName

    In the resource file:

    - en-US

    AppName: English Name

    - zh-CN

    AppName:       中文名

    Have fun!


    I build UWPs: Arrnage Pro, Cloud Resource Tools

    Tuesday, July 11, 2017 1:37 AM
  • Suddenly it mysteriously works. Not sure why, maybe something went wrong with the build system. I always pressed F5 or clicked the Debug button to debug the app.

    Ignorance is blissful

    Tuesday, July 11, 2017 1:52 AM