简体   繁体   中英

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.

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(); 
}); 

I think you are missing the processing for those locale file resources. It should be on the pages/home/home.js on ready handler. Like this

ready: function (element, options) {
    WinJS.Resources.processAll();
    .
    .
    .
}

This makes use of the localizations and replaces those to places where they are used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM