Cordova 带有非WinRT应用程序的WinJS.Resources.getString
我正在使用WinJS4.0开发Cordova应用程序。但是我尝试使用WinJS.Resources.getString,但它不起作用。它与我的Windows 8.1应用程序完美配合。Cordova 带有非WinRT应用程序的WinJS.Resources.getString,cordova,localization,windows-runtime,winjs,Cordova,Localization,Windows Runtime,Winjs,我正在使用WinJS4.0开发Cordova应用程序。但是我尝试使用WinJS.Resources.getString,但它不起作用。它与我的Windows 8.1应用程序完美配合。 有什么方法可以让我用在科尔多瓦身上吗?如果没有,我应该使用哪种替代解决方案?请给我一个答案。非常感谢。是的,您可以这样做,但不能直接做 在调用WinJS.UI.process之前,您需要读取resjson并设置全局“strings”变量: var loadLocalRessources = function (la
有什么方法可以让我用在科尔多瓦身上吗?如果没有,我应该使用哪种替代解决方案?请给我一个答案。非常感谢。是的,您可以这样做,但不能直接做 在调用WinJS.UI.process之前,您需要读取resjson并设置全局“strings”变量:
var loadLocalRessources = function (language) {
language = language || 'en';
return new WinJS.Promise(function (complete, error) {
var url = './strings/' + language + '/resources.resjson';
console.log('trying to load resources from ' + url);
WinJS.xhr({ url: url }).then(function (res) {
console.log('resource ok for ' + language);
try {
window.strings = JSON.parse(res.responseText);
} catch (exception) {
console.error('resource parse error ' + exception.message);
}
complete(window.strings);
}, function (err) {
console.error('resource load error for ' + language + ' ' + err.statusText);
if (language != 'en') {
data.loadLocalRessources('en').then(complete, error);
}
else {
error(err);
}
});
});
}