Преглед изворни кода

Add passing CKEditor language to CKFinder.

Maciej Gołaszewski пре 7 година
родитељ
комит
8e52f34081

+ 5 - 0
packages/ckeditor5-ckfinder/src/ckfindercommand.js

@@ -65,6 +65,11 @@ export default class CKFinderCommand extends Command {
 
 		options.chooseFiles = true;
 
+		// Pass the lang code to the CKFinder if not defined by user.
+		if ( !options.language ) {
+			options.language = editor.locale.language;
+		}
+
 		// The onInit method allows to extend CKFinder's behavior. It is used to attach event listeners to file choosing related events.
 		options.onInit = finder => {
 			finder.on( 'files:choose', evt => {

+ 55 - 3
packages/ckeditor5-ckfinder/tests/ckfindercommand.js

@@ -34,9 +34,6 @@ describe( 'CKFinderCommand', () => {
 
 				command = new CKFinderCommand( editor );
 
-				const schema = model.schema;
-				schema.extend( 'image' );
-
 				setModelData( model, '<paragraph>f[o]o</paragraph>' );
 			} );
 	} );
@@ -197,6 +194,61 @@ describe( 'CKFinderCommand', () => {
 			expect( openerMethodOptions ).to.have.property( 'connectorPath', connectorPath );
 		} );
 
+		it( 'should pass editor default language to the CKFinder instance', () => {
+			const spy = sinon.spy( window.CKFinder, 'modal' );
+			command.execute();
+
+			const openerMethodOptions = spy.args[ 0 ][ 0 ];
+
+			expect( openerMethodOptions ).to.have.property( 'language', 'en' );
+		} );
+
+		it( 'should pass editor language set by configuration to the CKFinder instance', () => {
+			const finderMock = {
+				on: ( eventName, callback ) => {
+					finderMock[ eventName ] = callback;
+				}
+			};
+
+			return VirtualTestEditor
+				.create( {
+					plugins: [ Paragraph, ImageEditing, ImageUploadEditing, LinkEditing, Notification ],
+					language: 'pl'
+				} )
+				.then( newEditor => {
+					editor = newEditor;
+
+					window.CKFinder = {
+						modal: config => {
+							config.onInit( finderMock );
+						}
+					};
+
+					command = new CKFinderCommand( editor );
+
+					setModelData( editor.model, '<paragraph>f[o]o</paragraph>' );
+					const spy = sinon.spy( window.CKFinder, 'modal' );
+
+					command.execute();
+
+					const openerMethodOptions = spy.args[ 0 ][ 0 ];
+
+					expect( openerMethodOptions ).to.have.property( 'language', 'pl' );
+				} );
+		} );
+
+		it( 'should not pass editor language if it is set in ckfinder.options', () => {
+			const spy = sinon.spy( window.CKFinder, 'modal' );
+
+			editor.config.set( 'ckfinder.options.language', 'pl' );
+
+			command.execute();
+
+			const openerMethodOptions = spy.args[ 0 ][ 0 ];
+
+			expect( openerMethodOptions ).to.have.property( 'language', 'pl' );
+		} );
+
 		it( 'should insert multiple chosen images as image widget', () => {
 			const url1 = 'foo/bar1.jpg';
 			const url2 = 'foo/bar2.jpg';