2020-08-10 13:16:03 +03:00
|
|
|
import {formatNumber} from './format-number';
|
|
|
|
import {helper} from '@ember/component/helper';
|
|
|
|
import {isBlank} from '@ember/utils';
|
|
|
|
import {pluralize} from 'ember-inflector';
|
|
|
|
|
2020-08-10 13:32:45 +03:00
|
|
|
export function ghPluralize(number, word, {withoutCount} = {}) {
|
2020-08-10 13:16:03 +03:00
|
|
|
let output = [];
|
|
|
|
|
|
|
|
if (!isBlank(number) && withoutCount !== true) {
|
|
|
|
output.push(formatNumber(number));
|
|
|
|
}
|
|
|
|
|
|
|
|
// default {{pluralize}} allows for {{pluralize "word"}} with no number
|
|
|
|
if (isBlank(number)) {
|
2020-08-10 13:32:45 +03:00
|
|
|
output.push(pluralize(word));
|
2020-08-10 13:16:03 +03:00
|
|
|
} else {
|
|
|
|
output.push(pluralize(number, word, {withoutCount: true}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return output.join(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
// like {{pluralize}} but formats the number according to current locale
|
|
|
|
export default helper(function ([number, word], {'without-count': withoutCount} = {}) {
|
2020-08-10 13:32:45 +03:00
|
|
|
return ghPluralize(number, word, {withoutCount});
|
2020-08-10 13:16:03 +03:00
|
|
|
});
|