8
0
Просмотр исходного кода

Other: Added support for plural rules that returns a boolean value.

Maciej Bukowski 5 лет назад
Родитель
Сommit
5194ed02fc

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

@@ -155,7 +155,7 @@ export function _translate( language, message, quantity = 1 ) {
 		return dictionary[ messageId ];
 	}
 
-	const pluralFormIndex = getPluralForm( quantity );
+	const pluralFormIndex = Number( getPluralForm( quantity ) );
 
 	// Note: The `translate` function is not responsible for replacing `%0, %1, ...` with values.
 	return dictionary[ messageId ][ pluralFormIndex ];

+ 13 - 0
packages/ckeditor5-utils/tests/translation-service.js

@@ -137,5 +137,18 @@ describe( 'translation-service', () => {
 			expect( _translate( 'pl', { string: 'Add space' }, 3 ) ).to.equal( 'Dodaj %0 spacje' );
 			expect( _translate( 'pl', { string: 'Add space' }, 13 ) ).to.equal( 'Dodaj %0 spacje' );
 		} );
+
+		it( 'should support a plural form rule that returns a boolean', () => {
+			add( 'pl', {
+				'Add space': [ 'Dodaj spację', 'Dodaj %0 spacje' ],
+				'Cancel': 'Anuluj'
+			}, n => n !== 1 );
+
+			expect( _translate( 'pl', { string: 'Add space' }, 1 ) ).to.equal( 'Dodaj spację' );
+
+			expect( _translate( 'pl', { string: 'Add space' }, 0 ) ).to.equal( 'Dodaj %0 spacje' );
+			expect( _translate( 'pl', { string: 'Add space' }, 3 ) ).to.equal( 'Dodaj %0 spacje' );
+			expect( _translate( 'pl', { string: 'Add space' }, 13 ) ).to.equal( 'Dodaj %0 spacje' );
+		} );
 	} );
 } );