Removed pluralize function

Replaced instance of the `pluralize` js function
with `n__` to follow our development guide.
This commit is contained in:
Ezekiel Kigbo 2019-07-24 17:39:18 +00:00 committed by Paul Slaughter
parent 945eb2aeee
commit 78d57823ca
6 changed files with 21 additions and 36 deletions

View File

@ -1,5 +1,5 @@
import $ from 'jquery';
import { pluralize } from './lib/utils/text_utility';
import { n__ } from '~/locale';
import { localTimeAgo } from './lib/utils/datetime_utility';
import Pager from './pager';
import axios from './lib/utils/axios_utils';
@ -90,9 +90,10 @@ export default class CommitsList {
.first()
.find('li.commit').length,
);
$commitsHeadersLast
.find('span.commits-count')
.text(`${commitsCount} ${pluralize('commit', commitsCount)}`);
.text(n__('%d commit', '%d commits', commitsCount));
}
localTimeAgo($processedData.find('.js-timeago'));

View File

@ -1,6 +1,7 @@
<script>
import { n__ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue';
import { pluralize, truncate } from '~/lib/utils/text_utility';
import { truncate } from '~/lib/utils/text_utility';
import UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue';
import { GlTooltipDirective } from '@gitlab/ui';
import { COUNT_OF_AVATARS_IN_GUTTER, LENGTH_OF_AVATAR_TOOLTIP } from '../constants';
@ -42,7 +43,7 @@ export default {
return '';
}
return pluralize(`${this.moreCount} more comment`, this.moreCount);
return n__('%d more comment', '%d more comments', this.moreCount);
},
},
methods: {

View File

@ -2,8 +2,7 @@ import $ from 'jquery';
import _ from 'underscore';
import timeago from 'timeago.js';
import dateFormat from 'dateformat';
import { pluralize } from './text_utility';
import { languageCode, s__, __ } from '../../locale';
import { languageCode, s__, __, n__ } from '../../locale';
window.timeago = timeago;
@ -231,14 +230,10 @@ export const timeIntervalInWords = intervalInSeconds => {
const secondsInteger = parseInt(intervalInSeconds, 10);
const minutes = Math.floor(secondsInteger / 60);
const seconds = secondsInteger - minutes * 60;
let text = '';
if (minutes >= 1) {
text = `${minutes} ${pluralize('minute', minutes)} ${seconds} ${pluralize('second', seconds)}`;
} else {
text = `${seconds} ${pluralize('second', seconds)}`;
}
return text;
const secondsText = n__('%d second', '%d seconds', seconds);
return minutes >= 1
? [n__('%d minute', '%d minutes', minutes), secondsText].join(' ')
: secondsText;
};
export const dateInWords = (date, abbreviated = false, hideYear = false) => {

View File

@ -28,14 +28,6 @@ export const highCountTrim = count => (count > 99 ? '99+' : count);
export const humanize = string =>
string.charAt(0).toUpperCase() + string.replace(/_/g, ' ').slice(1);
/**
* Adds an 's' to the end of the string when count is bigger than 0
* @param {String} str
* @param {Number} count
* @returns {String}
*/
export const pluralize = (str, count) => str + (count > 1 || count === 0 ? 's' : '');
/**
* Replaces underscores with dashes
* @param {*} str

View File

@ -95,11 +95,21 @@ msgid_plural "%d metrics"
msgstr[0] ""
msgstr[1] ""
msgid "%d minute"
msgid_plural "%d minutes"
msgstr[0] ""
msgstr[1] ""
msgid "%d more comment"
msgid_plural "%d more comments"
msgstr[0] ""
msgstr[1] ""
msgid "%d second"
msgid_plural "%d seconds"
msgstr[0] ""
msgstr[1] ""
msgid "%d staged change"
msgid_plural "%d staged changes"
msgstr[0] ""

View File

@ -29,20 +29,6 @@ describe('text_utility', () => {
});
});
describe('pluralize', () => {
it('should pluralize given string', () => {
expect(textUtils.pluralize('test', 2)).toBe('tests');
});
it('should pluralize when count is 0', () => {
expect(textUtils.pluralize('test', 0)).toBe('tests');
});
it('should not pluralize when count is 1', () => {
expect(textUtils.pluralize('test', 1)).toBe('test');
});
});
describe('dasherize', () => {
it('should replace underscores with dashes', () => {
expect(textUtils.dasherize('foo_bar_foo')).toEqual('foo-bar-foo');