1
给定一个返回数字的表达式或变量,有没有办法让当前语言环境的数字的复数类别?Angular i18n/ngPluralize是否有办法检索数字的复数类别?
喜欢的东西
// people.length == 1
ngPluralize.getCategory(people.length) // returns 'one'
给定一个返回数字的表达式或变量,有没有办法让当前语言环境的数字的复数类别?Angular i18n/ngPluralize是否有办法检索数字的复数类别?
喜欢的东西
// people.length == 1
ngPluralize.getCategory(people.length) // returns 'one'
的$locale
有rather tiny public API。但是,there is a $locale.pluralCat
method,所以你可以使用它。
angular.module('app', [])
.controller('LocaleCtrl', function($scope, $locale) {
$scope.locale = $locale.id;
$scope.getCategory = function(count) {
return $locale.pluralCat(count);
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.5.5/angular-locale_pl-pl.js"></script>
<div ng-app="app">
<div ng-controller="LocaleCtrl">
<h1>ng-pluralize category for locale {{ locale }}</h1>
<ul>
<li ng-repeat="count in [0, 1, 2, 3, 4, 5, 6]">
category for {{count}} is {{ getCategory(count) }}
</li>
</ul>
</div>
</div>
当然,如果你使用different locales的结果是不同的。
美丽!谢谢。 – bearfriend