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