Skip to content

Commit

Permalink
Merge pull request #414 from ckeditor/t/413
Browse files Browse the repository at this point in the history
Internal: Allowed reusing other packages' translations. Hotfix for #413.
  • Loading branch information
Reinmar committed Jun 22, 2018
2 parents d3ec548 + 0864408 commit 5a29ff0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
21 changes: 11 additions & 10 deletions packages/ckeditor5-dev-env/lib/translations/collect-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,23 @@ const utils = {
},

_validateContexts( contexts, translation ) {
const packageContext = contexts.get( translation.package );
const corePackageContext = contexts.get( corePackageName );
let error;

if ( !corePackageContext ) {
error = `${ corePackageName }/lang/contexts.json file is missing.`;
} else if ( !corePackageContext.content[ translation.key ] && !packageContext ) {
error = 'contexts.json file or context for the translation key is missing ' +
`(${ translation.package }, ${ translation.key }).`;
return `${ corePackageName }/lang/contexts.json file is missing.`;
}
// xxx
else if ( !corePackageContext.content[ translation.key ] && !packageContext.content[ translation.key ] ) {
error = `Context for the translation key is missing (${ translation.package }, ${ translation.key }).`;

let contextExists = false;

for ( const [ , currentPackageContext ] of contexts ) {
if ( currentPackageContext.content[ translation.key ] ) {
contextExists = true;
}
}

return error;
if ( !contextExists ) {
return `Context for the translation key is missing (${ translation.package }, ${ translation.key }).`;
}
}
};

Expand Down
30 changes: 15 additions & 15 deletions packages/ckeditor5-dev-env/tests/translations/collect-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,21 +134,6 @@ describe( 'collect-utils', () => {
] );
} );

it( 'should return an error when lang/contexts.json could be missing', () => {
const contexts = new Map( [
[ 'ckeditor5-core', { content: {} } ]
] );
const translations = [ {
package: 'ckeditor5-utils',
key: 'util'
} ];
const errors = utils.getMissingContextErrorMessages( contexts, translations );

expect( errors ).to.deep.equal( [
'contexts.json file or context for the translation key is missing (ckeditor5-utils, util).'
] );
} );

it( 'should return an error when the translation does not exist', () => {
const contexts = new Map( [
[ 'ckeditor5-core', { content: {} } ],
Expand Down Expand Up @@ -193,6 +178,21 @@ describe( 'collect-utils', () => {

expect( errors ).to.deep.equal( [] );
} );

it( 'should not return errors when translation exists in other package', () => {
const contexts = new Map( [
[ 'ckeditor5-core', { content: {} } ],
[ 'ckeditor5-heading', { content: {} } ],
[ 'ckeditor5-paragraph', { content: { paragraph: 'Paragraph' } } ]
] );
const translations = [ {
package: 'ckeditor5-heading',
key: 'paragraph'
} ];
const errors = utils.getMissingContextErrorMessages( contexts, translations );

expect( errors ).to.deep.equal( [] );
} );
} );

describe( 'getUnusedContextErrorMessages()', () => {
Expand Down

0 comments on commit 5a29ff0

Please sign in to comment.