Angular i18n/ngPluralize 中有没有办法检索数字的复数类别?
Is there a way in Angular i18n/ngPluralize to retrieve the plural category of a number?
给定一个 returns 数字的表达式或变量,有没有办法获取该数字在当前语言环境下的复数类别?
类似
// people.length == 1
ngPluralize.getCategory(people.length) // returns 'one'
$locale
有rather tiny public API. However, 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,结果就不一样了。
给定一个 returns 数字的表达式或变量,有没有办法获取该数字在当前语言环境下的复数类别?
类似
// people.length == 1
ngPluralize.getCategory(people.length) // returns 'one'
$locale
有rather tiny public API. However, 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,结果就不一样了。