-
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 #1031 from ckeditor/i/3846
Fix (translations): Align the number of plural forms to plural forms defined by a language in the `synchronizeTranslations()` function.
- Loading branch information
Showing
6 changed files
with
210 additions
and
27 deletions.
There are no files selected for viewing
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
22 changes: 22 additions & 0 deletions
22
packages/ckeditor5-dev-translations/lib/utils/getheaders.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,22 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import { getNPlurals, getFormula } from 'plural-forms'; | ||
|
||
/** | ||
* @param {string} languageCode | ||
* @param {string} localeCode | ||
* @returns {object} | ||
*/ | ||
export default function getHeaders( languageCode, localeCode ) { | ||
return { | ||
Language: localeCode, | ||
'Plural-Forms': [ | ||
`nplurals=${ getNPlurals( languageCode ) };`, | ||
`plural=${ getFormula( languageCode ) };` | ||
].join( ' ' ), | ||
'Content-Type': 'text/plain; charset=UTF-8' | ||
}; | ||
} |
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
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
48 changes: 48 additions & 0 deletions
48
packages/ckeditor5-dev-translations/tests/utils/getheaders.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,48 @@ | ||
/** | ||
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved. | ||
* For licensing, see LICENSE.md. | ||
*/ | ||
|
||
import { describe, expect, it, beforeEach, vi } from 'vitest'; | ||
import { getNPlurals, getFormula } from 'plural-forms'; | ||
import getHeaders from '../../lib/utils/getheaders.js'; | ||
|
||
vi.mock( 'plural-forms' ); | ||
|
||
describe( 'getHeaders()', () => { | ||
beforeEach( () => { | ||
vi.mocked( getNPlurals ).mockReturnValue( 4 ); | ||
vi.mocked( getFormula ).mockReturnValue( 'example plural formula' ); | ||
} ); | ||
|
||
it( 'should be a function', () => { | ||
expect( getHeaders ).toBeInstanceOf( Function ); | ||
} ); | ||
|
||
it( 'should return "Language" header', () => { | ||
const headers = getHeaders( 'en', 'en_GB' ); | ||
|
||
expect( headers ).toEqual( expect.objectContaining( { | ||
Language: 'en_GB' | ||
} ) ); | ||
} ); | ||
|
||
it( 'should return "Plural-Forms" header', () => { | ||
const headers = getHeaders( 'en', 'en_GB' ); | ||
|
||
expect( headers ).toEqual( expect.objectContaining( { | ||
'Plural-Forms': 'nplurals=4; plural=example plural formula;' | ||
} ) ); | ||
|
||
expect( getNPlurals ).toHaveBeenCalledWith( 'en' ); | ||
expect( getFormula ).toHaveBeenCalledWith( 'en' ); | ||
} ); | ||
|
||
it( 'should return "Content-Type" header', () => { | ||
const headers = getHeaders( 'en', 'en_GB' ); | ||
|
||
expect( headers ).toEqual( expect.objectContaining( { | ||
'Content-Type': 'text/plain; charset=UTF-8' | ||
} ) ); | ||
} ); | ||
} ); |
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