-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1034 from ckeditor/ci/3852
Fix (translations): Fixed `synchronizeTranslations()` function to fill new translation entries for English in `en.po` with texts collected from the source code.
- Loading branch information
Showing
4 changed files
with
114 additions
and
4 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
packages/ckeditor5-dev-translations/lib/utils/addtranslation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
/** | ||
* @param {object} options | ||
* @param {string} options.languageCode | ||
* @param {number} options.numberOfPluralForms | ||
* @param {TranslatableEntry} options.message | ||
* @returns {Array.<string>} | ||
*/ | ||
export default function addTranslation( { languageCode, numberOfPluralForms, message } ) { | ||
// English is the source (base) language, so set the translation value to the text collected from source code. | ||
if ( languageCode === 'en' ) { | ||
const msgstr = [ message.string ]; | ||
|
||
if ( message.plural ) { | ||
msgstr.push( message.plural ); | ||
} | ||
|
||
return msgstr; | ||
} | ||
|
||
// For other languages, pre-fill the translation value with an empty string which means that it requires translation. | ||
const msgstr = [ '' ]; | ||
|
||
if ( message.plural ) { | ||
msgstr.push( ...Array( numberOfPluralForms - 1 ).fill( '' ) ); | ||
} | ||
|
||
return msgstr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/ckeditor5-dev-translations/tests/utils/addtranslation.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import { beforeEach, describe, expect, it } from 'vitest'; | ||
import addTranslation from '../../lib/utils/addtranslation.js'; | ||
|
||
describe( 'addTranslation()', () => { | ||
let singularMessage, pluralMessage; | ||
|
||
beforeEach( () => { | ||
singularMessage = { | ||
string: 'Example message 1' | ||
}; | ||
|
||
pluralMessage = { | ||
string: 'Example message 2', | ||
plural: 'Example message 2 - plural form' | ||
}; | ||
} ); | ||
|
||
it( 'should be a function', () => { | ||
expect( addTranslation ).toBeInstanceOf( Function ); | ||
} ); | ||
|
||
it( 'should return translation (English, non-plural message)', () => { | ||
const result = addTranslation( { languageCode: 'en', numberOfPluralForms: 2, message: singularMessage } ); | ||
|
||
expect( result ).toEqual( [ 'Example message 1' ] ); | ||
} ); | ||
|
||
it( 'should return translation (English, plural message)', () => { | ||
const result = addTranslation( { languageCode: 'en', numberOfPluralForms: 2, message: pluralMessage } ); | ||
|
||
expect( result ).toEqual( [ 'Example message 2', 'Example message 2 - plural form' ] ); | ||
} ); | ||
|
||
it( 'should return translation (non-English, non-plural message)', () => { | ||
const result = addTranslation( { languageCode: 'pl', numberOfPluralForms: 4, message: singularMessage } ); | ||
|
||
expect( result ).toEqual( [ '' ] ); | ||
} ); | ||
|
||
it( 'should return translation (non-English, plural message)', () => { | ||
const result = addTranslation( { languageCode: 'pl', numberOfPluralForms: 4, message: pluralMessage } ); | ||
|
||
expect( result ).toEqual( [ '', '', '', '' ] ); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters