Angular - 在用户授权之前和之后使用静态 json 进行翻译 - 使用来自服务器的数据
Angular - Use static json for translations before the user authorized and after - use data from server
是否可以在用户授权之前和使用服务器数据后使用静态 json 进行翻译?
如果你使用angular-translate you can use $translateProvider
(or $translatePartialLoader
) to perform some asynchronous loading.
对我来说效果很好,看起来可以解决你正在尝试做的事情。
angular.module('contact')
.controller('ContactCtrl', function ($scope, $translatePartialLoader, $translate) {
$translatePartialLoader.addPart('contact');
$translate.refresh();
});
使用了以下内容:
if('user is not logged in') {
//get local file
return this.getLocalTranslation(refresh, lang);
}
var deferred = $q.defer();
else {
$http({
url: "" ;
method: "GET"
}).then(function(result) {
if(result.data.success === 'true') {
console.log(result.data);
} else {
console.error(result.data.message);
deferred.reject(result.data);
}
});
}
如果用户未登录 - 则使用本地文件,否则调用源表单服务器
是否可以在用户授权之前和使用服务器数据后使用静态 json 进行翻译?
如果你使用angular-translate you can use $translateProvider
(or $translatePartialLoader
) to perform some asynchronous loading.
对我来说效果很好,看起来可以解决你正在尝试做的事情。
angular.module('contact')
.controller('ContactCtrl', function ($scope, $translatePartialLoader, $translate) {
$translatePartialLoader.addPart('contact');
$translate.refresh();
});
使用了以下内容:
if('user is not logged in') {
//get local file
return this.getLocalTranslation(refresh, lang);
}
var deferred = $q.defer();
else {
$http({
url: "" ;
method: "GET"
}).then(function(result) {
if(result.data.success === 'true') {
console.log(result.data);
} else {
console.error(result.data.message);
deferred.reject(result.data);
}
});
}
如果用户未登录 - 则使用本地文件,否则调用源表单服务器