Removed pluralize function
Replaced instance of the `pluralize` js function with `n__` to follow our development guide.
This commit is contained in:
parent
945eb2aeee
commit
78d57823ca
|
@ -1,5 +1,5 @@
|
||||||
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 {
|
||||||
.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'));
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<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 {
|
||||||
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';
|
||||||
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 => {
|
||||||
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);
|
||||||
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"
|
||||||
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', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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');
|
||||||
|
|
Loading…
Reference in New Issue