locked
PrimaryLanguageOverride in runtime on JavaScript

    Question

  • Can't find any "out of box" example how to override language in JS.

    If to change language in control panel - everything works well. I see content in another language.

    Cause I have add supported languages to manifest and have add this piece of code:

    WinJS.Application.onloaded = function () {
        WinJS.Resources.processAll();
    }
    As I know from C# after changing Primary Language App should be restarted. But In JS even after restart this code doesn't works..
      Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "en";
    What shell I do to force this code work?
    Sunday, June 09, 2013 7:55 AM

Answers

  • This works for me when testing different languages without switching through control panel:

    Note the lowercase primaryLanguageOverride and that it is done just before loading the resources.

    Also note the registry with the contextchanged event, this changes the app language on the fly when the user switches the language through control panel.

    app.onactivated = function (args) {
            args.setPromise(WinJS.UI.processAll().done(function () {
                // Load resources.
                loadResources();
                // Enable listener so they get updated when user changes language selection.
                WinJS.Resources.addEventListener("contextchanged", loadResources);
                // ...
            });
    };

    function loadResources() {

      // Test French language, comment out to use default language.

      Windows.Globalization.ApplicationLanguages.primaryLanguageOverride = "fr";
      WinJS.Resources.processAll();
    };

    Thursday, June 13, 2013 9:37 AM

All replies

  • This works for me when testing different languages without switching through control panel:

    Note the lowercase primaryLanguageOverride and that it is done just before loading the resources.

    Also note the registry with the contextchanged event, this changes the app language on the fly when the user switches the language through control panel.

    app.onactivated = function (args) {
            args.setPromise(WinJS.UI.processAll().done(function () {
                // Load resources.
                loadResources();
                // Enable listener so they get updated when user changes language selection.
                WinJS.Resources.addEventListener("contextchanged", loadResources);
                // ...
            });
    };

    function loadResources() {

      // Test French language, comment out to use default language.

      Windows.Globalization.ApplicationLanguages.primaryLanguageOverride = "fr";
      WinJS.Resources.processAll();
    };

    Thursday, June 13, 2013 9:37 AM
  • Thank you very much!!

    With lowercase "p" it works!

    Thursday, June 13, 2013 1:42 PM