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

Tests: Removed usage of deprecated API.

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

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

@@ -9,7 +9,7 @@
 
 /* globals console */
 
-import { translate } from './translation-service';
+import { _translate } from './translation-service';
 
 const RTL_LANGUAGE_CODES = [ 'ar', 'fa', 'he', 'ku', 'ug' ];
 
@@ -153,7 +153,7 @@ export default class Locale {
 		const hasPluralForm = !!message.plural;
 		const amount = hasPluralForm ? values[ 0 ] : 1;
 
-		let translatedString = translate( this.uiLanguage, message, amount );
+		let translatedString = _translate( this.uiLanguage, message, amount );
 
 		if ( values ) {
 			translatedString = translatedString.replace( /%(\d+)/g, ( match, index ) => {

+ 3 - 9
packages/ckeditor5-utils/src/translation-service.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-/* globals window, console */
+/* globals window */
 
 /**
  * @module utils/translation-service
@@ -80,19 +80,13 @@ export function add( language, translations, getPluralForm ) {
  * 		translate( 'en', { string: 'Add a space', plural: 'Add %0 spaces' }, 1 ); // 'Add a space'
  * 		translate( 'en', { string: 'Add a space', plural: 'Add %0 spaces' }, 3 ); // 'Add %0 spaces'
  *
+ * @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.
  * @returns {String} Translated sentence.
  */
-export function translate( language, message, amount = 1 ) {
-	if ( typeof message === 'string' ) {
-		// TODO
-		console.warn( 'deprecated usage' );
-
-		message = { string: message };
-	}
-
+export function _translate( language, message, amount = 1 ) {
 	const numberOfLanguages = getNumberOfLanguages();
 
 	if ( numberOfLanguages === 1 ) {

+ 26 - 36
packages/ckeditor5-utils/tests/translation-service.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  */
 
-import { translate, add, _clear } from '../src/translation-service';
+import { _translate, add, _clear } from '../src/translation-service';
 
 describe( 'translation-service', () => {
 	afterEach( () => {
@@ -15,8 +15,8 @@ describe( 'translation-service', () => {
 			add( 'pl', { 'foo': 'foo_pl' } );
 			add( 'pl', { 'bar': 'bar_pl' } );
 
-			const translatedFoo = translate( 'pl', { string: 'foo' } );
-			const translatedBar = translate( 'pl', { string: 'bar' } );
+			const translatedFoo = _translate( 'pl', { string: 'foo' } );
+			const translatedBar = _translate( 'pl', { string: 'bar' } );
 
 			expect( translatedFoo ).to.equal( 'foo_pl' );
 			expect( translatedBar ).to.equal( 'bar_pl' );
@@ -26,7 +26,7 @@ describe( 'translation-service', () => {
 			add( 'pl', { 'foo': 'First' } );
 			add( 'pl', { 'foo': 'Second' } );
 
-			const translatedFoo = translate( 'pl', { string: 'foo' } );
+			const translatedFoo = _translate( 'pl', { string: 'foo' } );
 
 			expect( translatedFoo ).to.equal( 'Second' );
 		} );
@@ -39,10 +39,10 @@ describe( 'translation-service', () => {
 			// eslint-disable-next-line no-nested-ternary
 			add( 'pl', {}, n => n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 ) ? 1 : 2 );
 
-			expect( translate( 'pl', 'Add space', 0 ) ).to.equal( 'Dodaj %0 spacji' );
-			expect( translate( 'pl', 'Add space', 1 ) ).to.equal( 'Dodaj spację' );
-			expect( translate( 'pl', 'Add space', 3 ) ).to.equal( 'Dodaj %0 spacje' );
-			expect( translate( 'pl', 'Add space', 13 ) ).to.equal( 'Dodaj %0 spacji' );
+			expect( _translate( 'pl', { string: 'Add space' }, 0 ) ).to.equal( 'Dodaj %0 spacji' );
+			expect( _translate( 'pl', { string: 'Add space' }, 1 ) ).to.equal( 'Dodaj spację' );
+			expect( _translate( 'pl', { string: 'Add space' }, 3 ) ).to.equal( 'Dodaj %0 spacje' );
+			expect( _translate( 'pl', { string: 'Add space' }, 13 ) ).to.equal( 'Dodaj %0 spacji' );
 		} );
 	} );
 
@@ -58,35 +58,35 @@ describe( 'translation-service', () => {
 				'Cancel': 'Cancel'
 			} );
 
-			const translatedCancelPL = translate( 'pl', { string: 'Cancel' } );
-			const translatedCancelEN = translate( 'en', { string: 'Cancel' } );
+			const translatedCancelPL = _translate( 'pl', { string: 'Cancel' } );
+			const translatedCancelEN = _translate( 'en', { string: 'Cancel' } );
 
 			expect( translatedCancelPL ).to.be.equal( 'Anuluj' );
 			expect( translatedCancelEN ).to.be.equal( 'Cancel' );
 		} );
 
 		it( 'should return the original message string if no translation exists for the given message', () => {
-			const translatedBold = translate( 'pl', { string: 'Bold' } );
+			const translatedBold = _translate( 'pl', { string: 'Bold' } );
 
 			expect( translatedBold ).to.be.equal( 'Bold' );
 		} );
 
 		it( 'should return the correct plural form of english message if no translation exists for the given message', () => {
-			const addSpaces = translate( 'pl', { string: 'Add a space', plural: 'Add %0 spaces' }, 3 );
-			const addASpace = translate( 'pl', { string: 'Add a space', plural: 'Add %0 spaces' }, 1 );
+			const addSpaces = _translate( 'pl', { string: 'Add a space', plural: 'Add %0 spaces' }, 3 );
+			const addASpace = _translate( 'pl', { string: 'Add a space', plural: 'Add %0 spaces' }, 1 );
 
 			expect( addSpaces ).to.be.equal( 'Add %0 spaces' );
 			expect( addASpace ).to.be.equal( 'Add a space' );
 		} );
 
 		it( 'should return the original message string if a translation for the target language does not exist' +
-			'but translation doesn\'t', () => {
+		'but translation doesn\'t', () => {
 			add( 'pl', {
 				'OK': 'OK',
 				'Cancel': 'Anuluj'
 			} );
 
-			const translatedBold = translate( 'pl', { string: 'Bold' } );
+			const translatedBold = _translate( 'pl', { string: 'Bold' } );
 
 			expect( translatedBold ).to.be.equal( 'Bold' );
 		} );
@@ -97,7 +97,7 @@ describe( 'translation-service', () => {
 				'Cancel': 'Anuluj'
 			} );
 
-			const translatedCancel = translate( 'de', { string: 'Cancel' } );
+			const translatedCancel = _translate( 'de', { string: 'Cancel' } );
 
 			expect( translatedCancel ).to.be.equal( 'Anuluj' );
 		} );
@@ -107,22 +107,11 @@ describe( 'translation-service', () => {
 				'foo_bar': 'foo-bar-translation'
 			} );
 
-			const translatedFooBar = translate( 'pl', { string: 'foo', context: 'bar' } );
+			const translatedFooBar = _translate( 'pl', { string: 'foo', context: 'bar' } );
 
 			expect( translatedFooBar ).to.equal( 'foo-bar-translation' );
 		} );
 
-		it( 'should support a deprecated form of using translate() function with string as a message', () => {
-			add( 'pl', {
-				'OK': 'OK',
-				'Cancel': 'Anuluj'
-			} );
-
-			const translation = translate( 'pl', 'Cancel' );
-
-			expect( translation ).to.equal( 'Anuluj' );
-		} );
-
 		it( 'should return the correct plural form of the message based on the provided function', () => {
 			add( 'pl', {
 				'Add space': [ 'Dodaj spację', 'Dodaj %0 spacje', 'Dodaj %0 spacji' ],
@@ -130,10 +119,10 @@ describe( 'translation-service', () => {
 				// eslint-disable-next-line no-nested-ternary
 			}, n => n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 ) ? 1 : 2 );
 
-			expect( translate( 'pl', 'Add space', 0 ) ).to.equal( 'Dodaj %0 spacji' );
-			expect( translate( 'pl', 'Add space', 1 ) ).to.equal( 'Dodaj spację' );
-			expect( translate( 'pl', 'Add space', 3 ) ).to.equal( 'Dodaj %0 spacje' );
-			expect( translate( 'pl', 'Add space', 13 ) ).to.equal( 'Dodaj %0 spacji' );
+			expect( _translate( 'pl', { string: 'Add space' }, 0 ) ).to.equal( 'Dodaj %0 spacji' );
+			expect( _translate( 'pl', { string: 'Add space' }, 1 ) ).to.equal( 'Dodaj spację' );
+			expect( _translate( 'pl', { string: 'Add space' }, 3 ) ).to.equal( 'Dodaj %0 spacje' );
+			expect( _translate( 'pl', { string: 'Add space' }, 13 ) ).to.equal( 'Dodaj %0 spacji' );
 		} );
 
 		it( 'should return a plural form based on rules for English if no function to determine the plural form was provided', () => {
@@ -142,10 +131,11 @@ describe( 'translation-service', () => {
 				'Cancel': 'Anuluj'
 			} );
 
-			expect( translate( 'pl', 'Add space', 0 ) ).to.equal( 'Dodaj %0 spacje' );
-			expect( translate( 'pl', 'Add space', 1 ) ).to.equal( 'Dodaj spację' );
-			expect( translate( 'pl', 'Add space', 3 ) ).to.equal( 'Dodaj %0 spacje' );
-			expect( translate( 'pl', 'Add space', 13 ) ).to.equal( 'Dodaj %0 spacje' );
+			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' );
 		} );
 	} );
 } );