Commit 78d57823 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo Committed by Paul Slaughter

Removed pluralize function

Replaced instance of the `pluralize` js function
with `n__` to follow our development guide.
parent 945eb2ae
import $ from 'jquery'; import $ from 'jquery';
import { pluralize } from './lib/utils/text_utility'; import { n__ } from '~/locale';
import { localTimeAgo } from './lib/utils/datetime_utility'; import { localTimeAgo } from './lib/utils/datetime_utility';
import Pager from './pager'; import Pager from './pager';
import axios from './lib/utils/axios_utils'; import axios from './lib/utils/axios_utils';
...@@ -90,9 +90,10 @@ export default class CommitsList { ...@@ -90,9 +90,10 @@ export default class CommitsList {
.first() .first()
.find('li.commit').length, .find('li.commit').length,
); );
$commitsHeadersLast $commitsHeadersLast
.find('span.commits-count') .find('span.commits-count')
.text(`${commitsCount} ${pluralize('commit', commitsCount)}`); .text(n__('%d commit', '%d commits', commitsCount));
} }
localTimeAgo($processedData.find('.js-timeago')); localTimeAgo($processedData.find('.js-timeago'));
......
<script> <script>
import { n__ } from '~/locale';
import Icon from '~/vue_shared/components/icon.vue'; 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 UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue';
import { GlTooltipDirective } from '@gitlab/ui'; import { GlTooltipDirective } from '@gitlab/ui';
import { COUNT_OF_AVATARS_IN_GUTTER, LENGTH_OF_AVATAR_TOOLTIP } from '../constants'; import { COUNT_OF_AVATARS_IN_GUTTER, LENGTH_OF_AVATAR_TOOLTIP } from '../constants';
...@@ -42,7 +43,7 @@ export default { ...@@ -42,7 +43,7 @@ export default {
return ''; return '';
} }
return pluralize(`${this.moreCount} more comment`, this.moreCount); return n__('%d more comment', '%d more comments', this.moreCount);
}, },
}, },
methods: { methods: {
......
...@@ -2,8 +2,7 @@ import $ from 'jquery'; ...@@ -2,8 +2,7 @@ import $ from 'jquery';
import _ from 'underscore'; import _ from 'underscore';
import timeago from 'timeago.js'; import timeago from 'timeago.js';
import dateFormat from 'dateformat'; import dateFormat from 'dateformat';
import { pluralize } from './text_utility'; import { languageCode, s__, __, n__ } from '../../locale';
import { languageCode, s__, __ } from '../../locale';
window.timeago = timeago; window.timeago = timeago;
...@@ -231,14 +230,10 @@ export const timeIntervalInWords = intervalInSeconds => { ...@@ -231,14 +230,10 @@ export const timeIntervalInWords = intervalInSeconds => {
const secondsInteger = parseInt(intervalInSeconds, 10); const secondsInteger = parseInt(intervalInSeconds, 10);
const minutes = Math.floor(secondsInteger / 60); const minutes = Math.floor(secondsInteger / 60);
const seconds = secondsInteger - minutes * 60; const seconds = secondsInteger - minutes * 60;
let text = ''; const secondsText = n__('%d second', '%d seconds', seconds);
return minutes >= 1
if (minutes >= 1) { ? [n__('%d minute', '%d minutes', minutes), secondsText].join(' ')
text = `${minutes} ${pluralize('minute', minutes)} ${seconds} ${pluralize('second', seconds)}`; : secondsText;
} else {
text = `${seconds} ${pluralize('second', seconds)}`;
}
return text;
}; };
export const dateInWords = (date, abbreviated = false, hideYear = false) => { export const dateInWords = (date, abbreviated = false, hideYear = false) => {
......
...@@ -28,14 +28,6 @@ export const highCountTrim = count => (count > 99 ? '99+' : count); ...@@ -28,14 +28,6 @@ export const highCountTrim = count => (count > 99 ? '99+' : count);
export const humanize = string => export const humanize = string =>
string.charAt(0).toUpperCase() + string.replace(/_/g, ' ').slice(1); 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 * Replaces underscores with dashes
* @param {*} str * @param {*} str
......
...@@ -95,11 +95,21 @@ msgid_plural "%d metrics" ...@@ -95,11 +95,21 @@ msgid_plural "%d metrics"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
msgid "%d minute"
msgid_plural "%d minutes"
msgstr[0] ""
msgstr[1] ""
msgid "%d more comment" msgid "%d more comment"
msgid_plural "%d more comments" msgid_plural "%d more comments"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
msgid "%d second"
msgid_plural "%d seconds"
msgstr[0] ""
msgstr[1] ""
msgid "%d staged change" msgid "%d staged change"
msgid_plural "%d staged changes" msgid_plural "%d staged changes"
msgstr[0] "" msgstr[0] ""
......
...@@ -29,20 +29,6 @@ describe('text_utility', () => { ...@@ -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', () => { describe('dasherize', () => {
it('should replace underscores with dashes', () => { it('should replace underscores with dashes', () => {
expect(textUtils.dasherize('foo_bar_foo')).toEqual('foo-bar-foo'); expect(textUtils.dasherize('foo_bar_foo')).toEqual('foo-bar-foo');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment