问题描述
你好我试图本地化为多元化的字符串角。我使用的NG-复数指令来处理多元化和本地化我根据用户区域传递字符串指令在运行时。但是我得到错误类型错误:对象#没有方法'一'即使$范围装有翻译strings.Following是我的html code,
Hi I am trying to localize the strings for pluralization in Angular. I am using ng-pluralize directive to handle pluralization and for localizations I am passing the strings to the directive at runtime based on user locale. But I am getting error "TypeError: Object # has no method 'one'" even if the $scope is loaded with translated strings.Following is my html code,
<input class="input-text" type="number" ng-model="candyCount" ng-keypress="loadStrings()"/>
<ng-pluralize count = "candyCount" when = "translateStrings" ></ng-pluralize>
的Javascript code
Javascript code
myApp.controller(‘MyCtrl’,function($scope){
$scope.loadStrings = function(){
$scope.translateStrings = null;
if (userLocale == "en-us"){
$scope.translateStrings =
{'0': '0 candy for sale','one': '1 candy for sale.','other': '{} candies for sale.'} ;
debugger;
}
else if (userLocale == "de-de"){
$scope.translateStrings = {'0': '0 Süßigkeiten ausgewählt',
'one': '1 Süßigkeiten zum Verkauf',
'other': '{} Süßigkeiten zum Verkauf.'
};
debugger;
}
}
});
我已经加入调试器每个条件块,所以当我在控制台检查$ scope.translateStrings,我得到作为输出,
对于EN-US:
I have added debugger to every condition block, so when I check for $scope.translateStrings in the console, I get output as,For en-us:
$scope.translateStrings
{'0': '0 candy for sale','one': '1 candy for sale.','other': '{} candies for sale.'}
是不是因为指令没有得到与最新更新的字符串,还是我走错了地方。
Is it because the directive is not getting updated with the latest strings, or am I going wrong somewhere.
推荐答案
如果你想翻译串的异步加载,你需要重新编译NG-复数。
If you want async loading of translation string you need to recompile ng-pluralize.
下面是一个演示:
这篇关于有翻译错误NG-复数:&QUOT;类型错误&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!