Parcourir la source

Other: Reworded amount to quantity in a few places.

Maciej Bukowski il y a 5 ans
Parent
commit
d79dbf54ea

+ 2 - 2
packages/ckeditor5-utils/src/locale.js

@@ -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 );
 	}

+ 7 - 7
packages/ckeditor5-utils/src/translation-service.js

@@ -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();
@@ -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;
 		}
@@ -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 ];

+ 2 - 2
packages/ckeditor5-utils/tests/locale.js

@@ -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 ] );