Search code examples
visual-studiocordovalocalizationwinjsmsdn

Localization in Cordova+WinJS application


I'm try to build sample WinJS application with "WinJS Navigation Template for Apache Cordova" ( https://code.msdn.microsoft.com/windowsapps/WinJS-Navigation-Template-50112ea9/view/SourceCode ).

What is a right way to add localization to this application? Standard for WinJS way - use strings/en-US/resources.resjson - doesn't work.


Solution

  • The reason WinJS.Resources.processAll() does not seem to work in a Cordova app is because the WinRT runtime is not available in browser-hosted applications.

    This is not directly written in the documentation, but is implied in the Application resources and localization sample:

    // WinRT is not available in the web compartment, so we must load strings ourselves 
    // File based resources can be used to load the correct strings 
    WinJS.xhr({ url: '/strings/resources.json' }).done(function (response) { 
        strings = JSON.parse(response.responseText); 
    
        WinJS.Resources.processAll(); 
        showMessage(); 
    });