Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Other: Reworded amount to quantity in a few places.
Browse files Browse the repository at this point in the history
  • Loading branch information
ma2ciek committed Apr 21, 2020
1 parent 7797511 commit 33acb99
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ export default class Locale {
}

const hasPluralForm = !!message.plural;
const amount = hasPluralForm ? values[ 0 ] : 1;
const quantity = hasPluralForm ? values[ 0 ] : 1;

const translatedString = _translate( this.uiLanguage, message, amount );
const translatedString = _translate( this.uiLanguage, message, quantity );

return interpolateString( translatedString, values );
}
Expand Down
14 changes: 7 additions & 7 deletions src/translation-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ export function add( language, translations, getPluralForm ) {
* @protected
* @param {String} language Target language.
* @param {module:utils/translation-service~Message|String} message A message that will be translated.
* @param {Number} [amount] A number of elements for which a plural form should be picked from the target language dictionary.
* @param {Number} [quantity] A number of elements for which a plural form should be picked from the target language dictionary.
* @returns {String} Translated sentence.
*/
export function _translate( language, message, amount = 1 ) {
if ( typeof amount !== 'number' ) {
export function _translate( language, message, quantity = 1 ) {
if ( typeof quantity !== 'number' ) {
/**
* The incorrect value has been passed to the `translation` function. This probably was caused
* by the incorrect message interpolation of a plural form. Note that for messages supporting plural forms
* the second argument of the `t()` function should always be a number or an array with number as the first element.
*
* @error translation-service-amount-not-a-number
* @error translation-service-quantity-not-a-number
*/
throw new CKEditorError( 'translation-service-amount-not-a-number: Expecting `amount` to be a number.', null, { amount } );
throw new CKEditorError( 'translation-service-quantity-not-a-number: Expecting `quantity` to be a number.', null, { quantity } );
}

const numberOfLanguages = getNumberOfLanguages();
Expand All @@ -144,7 +144,7 @@ export function _translate( language, message, amount = 1 ) {
message.string;

if ( numberOfLanguages === 0 || !hasTranslation( language, messageId ) ) {
if ( amount !== 1 ) {
if ( quantity !== 1 ) {
// Return the default plural form that was passed in the `message.plural` parameter.
return message.plural;
}
Expand All @@ -159,7 +159,7 @@ export function _translate( language, message, amount = 1 ) {
return dictionary[ messageId ];
}

const pluralFormIndex = getPluralForm( amount );
const pluralFormIndex = getPluralForm( quantity );

// Note: The `translate` function is not responsible for replacing `%0, %1, ...` with values.
return dictionary[ messageId ][ pluralFormIndex ];
Expand Down
4 changes: 2 additions & 2 deletions tests/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ describe( 'Locale', () => {

expectToThrowCKEditorError( () => {
t( { string: 'Add space', plural: 'Add %0 spaces' }, 'space' );
}, /translation-service-amount-not-a-number:/, null, { amount: 'space' } );
}, /translation-service-quantity-not-a-number:/, null, { quantity: 'space' } );

expectToThrowCKEditorError( () => {
t( { string: 'Add space', plural: 'Add %0 spaces' }, [ 'space' ] );
}, /translation-service-amount-not-a-number:/, null, { amount: 'space' } );
}, /translation-service-quantity-not-a-number:/, null, { quantity: 'space' } );

expect( () => {
t( { string: 'Add space', plural: 'Add %0 spaces' }, [ 3 ] );
Expand Down

0 comments on commit 33acb99

Please sign in to comment.