Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ckeditor/ckeditor5-dev-utils

Package Overview
Dependencies
Maintainers
1
Versions
261
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckeditor/ckeditor5-dev-utils - npm Package Compare versions

Comparing version 2.5.0 to 2.5.1

tests/translations/findoriginalstrings.js

2

lib/translations/createdictionaryfrompofilecontent.js

@@ -16,3 +16,3 @@ /**

*/
module.exports = function createDicitionaryFromPoFileContent( poFileContent ) {
module.exports = function createDictionaryFromPoFileContent( poFileContent ) {
const po = PO.parse( poFileContent );

@@ -19,0 +19,0 @@

@@ -10,2 +10,3 @@ /**

const walk = require( 'acorn/dist/walk' );
const logger = require( '../logger' )();

@@ -26,3 +27,3 @@ module.exports = function findOriginalStrings( source ) {

if ( node.arguments[ 0 ].type !== 'Literal' ) {
console.error( 'First t() call argument should be a string literal.' );
logger.error( 'First t() call argument should be a string literal.' );

@@ -29,0 +30,0 @@ return;

@@ -11,4 +11,4 @@ /**

findOriginalStrings: require( './findoriginalstrings' ),
createDicitionaryFromPoFileContent: require( './createdictionaryfrompofilecontent' ),
createDictionaryFromPoFileContent: require( './createdictionaryfrompofilecontent' ),
cleanPoFileContent: require( './cleanpofilecontent' )
};

@@ -10,6 +10,7 @@ /**

const fs = require( 'fs' );
const createDicitionaryFromPoFileContent = require( './createdictionaryfrompofilecontent' );
const createDictionaryFromPoFileContent = require( './createdictionaryfrompofilecontent' );
const acorn = require( 'acorn' );
const walk = require( 'acorn/dist/walk' );
const escodegen = require( 'escodegen' );
const logger = require( '../logger' )();

@@ -21,3 +22,3 @@ /**

/**
* @param {String} langauge Target language.
* @param {String} language Target language.
*/

@@ -44,3 +45,3 @@ constructor( language ) {

this._laodPoFile( pathToPoFile );
this._loadPoFile( pathToPoFile );
}

@@ -74,3 +75,3 @@

if ( node.arguments[ 0 ].type !== 'Literal' ) {
console.error( 'First t() call argument should be a string literal.' );
logger.error( 'First t() call argument should be a string literal.' );

@@ -91,3 +92,5 @@ return;

escodegen.attachComments( ast, comments, tokens );
const output = escodegen.generate( ast, { comment: true } );
const output = escodegen.generate( ast, {
comment: true
} );

@@ -98,3 +101,3 @@ return output;

// Loads translations from the po file.
_laodPoFile( pathToPoFile ) {
_loadPoFile( pathToPoFile ) {
if ( !fs.existsSync( pathToPoFile ) ) {

@@ -105,3 +108,3 @@ return;

const poFileContent = fs.readFileSync( pathToPoFile, 'utf-8' );
const parsedTranslationFile = createDicitionaryFromPoFileContent( poFileContent );
const parsedTranslationFile = createDictionaryFromPoFileContent( poFileContent );

@@ -118,3 +121,3 @@ for ( const translationKey in parsedTranslationFile ) {

if ( !translation ) {
console.error( `Missing translation for: ${ originalString }.` );
logger.error( `Missing translation for: ${ originalString }.` );

@@ -121,0 +124,0 @@ translation = originalString;

{
"name": "@ckeditor/ckeditor5-dev-utils",
"version": "2.5.0",
"version": "2.5.1",
"description": "Utils for CKEditor 5 development tools packages.",

@@ -5,0 +5,0 @@ "keywords": [],

@@ -34,3 +34,14 @@ /**

} );
it( 'should skip the objects that do not contain msgstr property', () => {
const result = createDicitionaryFromPoFileContent( [
`msgctxt "Label for the Save button."`,
`msgid "Save"`,
`msgstr ""`,
``,
].join( '\n' ) );
expect( result ).to.deep.equal( {} );
} );
} );
} );

@@ -14,12 +14,37 @@ /**

const path = require( 'path' );
const TranslationService = require( '../../lib/translations/translationservice' );
const proxyquire = require( 'proxyquire' );
const mockery = require( 'mockery' );
describe( 'translations', () => {
describe( 'TranslationService', () => {
let translationService;
let sandbox;
const sandbox = sinon.sandbox.create();
let translationService, stubs;
let files, fileContents;
beforeEach( () => {
sandbox = sinon.sandbox.create();
translationService = new TranslationService();
mockery.enable( {
useCleanCache: true,
warnOnReplace: false,
warnOnUnregistered: false
} );
stubs = {
logger: {
info: sandbox.stub(),
warning: sandbox.stub(),
error: sandbox.stub()
},
fs: {
existsSync: path => files.includes( path ),
readFileSync: path => fileContents[ path ]
}
};
mockery.registerMock( 'fs', stubs.fs );
const TranslationService = proxyquire( '../../lib/translations/translationservice', {
'../logger': () => stubs.logger,
} );
translationService = new TranslationService( 'pl' );
} );

@@ -29,20 +54,39 @@

sandbox.restore();
mockery.disable();
} );
describe( 'loadPackage()', () => {
it( 'should load po file from the package', () => {
const loadPoFileSpy = sinon.spy();
sandbox.stub( translationService, '_laodPoFile', loadPoFileSpy );
it( 'should load po file from the package and load translations', () => {
const pathToTranslations = path.join( 'pathToPackage', 'lang', 'translations', 'pl.po' );
files = [ pathToTranslations ];
fileContents = {
[ pathToTranslations ]: [
`msgctxt "Label for the Save button."`,
`msgid "Save"`,
`msgstr "Zapisz"`,
''
].join( '\n' )
};
translationService.loadPackage( 'pathToPackage' );
sinon.assert.calledWith(
loadPoFileSpy,
path.join( 'pathToPackage', 'lang', 'translations', this.language + '.po' )
);
expect( Array.from( translationService.dictionary ) ).to.deep.equal( [
[ 'Save', 'Zapisz' ]
] );
} );
it( 'should do nothing if the po file does not exist', () => {
files = [];
fileContents = {};
translationService.loadPackage( 'pathToPackage' );
expect( Array.from( translationService.dictionary ) ).to.deep.equal( [] );
} );
it( 'should load po file from the package only once', () => {
const loadPoFileSpy = sinon.spy();
sandbox.stub( translationService, '_laodPoFile', loadPoFileSpy );
sandbox.stub( translationService, '_loadPoFile', loadPoFileSpy );

@@ -74,4 +118,23 @@ translationService.loadPackage( 'pathToPackage' );

} );
it( 'should lg the error and keep original string if the translation misses', () => {
const source = `t( 'Cancel' )`;
const result = translationService.translateSource( source );
expect( result ).to.equal( `t('Cancel');` );
sinon.assert.calledOnce( stubs.logger.error );
sinon.assert.calledWithExactly( stubs.logger.error, 'Missing translation for: Cancel.' );
} );
it( 'should throw an error when the t is called with the variable', () => {
const source = `const cancel = 'Cancel';t( cancel );`;
const result = translationService.translateSource( source );
expect( result ).to.equal( `const cancel = 'Cancel';t( cancel );` );
sinon.assert.calledOnce( stubs.logger.error );
sinon.assert.calledWithExactly( stubs.logger.error, 'First t() call argument should be a string literal.' );
} );
} );
} );
} );
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc