Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 22079dd

Browse files
authored
Merge pull request #187 from ckeditor/t/ckeditor5/1151
Feature: Allowed configuration of the editor content language via `conifg.language`. See ckeditor/ckeditor5#1151.
2 parents 5d85eaf + 1808a3c commit 22079dd

File tree

3 files changed

+58
-12
lines changed

3 files changed

+58
-12
lines changed

src/editor/editor.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,16 @@ export default class Editor {
9191
*/
9292
this.commands = new CommandCollection();
9393

94+
const languageConfig = this.config.get( 'language' ) || {};
95+
9496
/**
9597
* @readonly
9698
* @member {module:utils/locale~Locale}
9799
*/
98-
this.locale = new Locale( this.config.get( 'language' ) );
100+
this.locale = new Locale( {
101+
uiLanguage: typeof languageConfig === 'string' ? languageConfig : languageConfig.ui,
102+
contentLanguage: this.config.get( 'language.content' )
103+
} );
99104

100105
/**
101106
* Shorthand for {@link module:utils/locale~Locale#t}.

src/editor/editorconfig.jsdoc

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,17 @@
167167
*/
168168

169169
/**
170-
* The editor UI's language.
170+
* The language of the editor UI and its content.
171171
*
172-
* The language code is defined in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) standard.
173-
* CKEditor 5 currently supports around 20 languages and the number is growing.
172+
* Note: You do not have to specify this option if your build is optimized for one UI language or if it is
173+
* the default language (English is the default language for CDN builds), unless you want to change
174+
* the language of your content.
174175
*
175-
* Note: You do not have to specify this option if your build is optimized for one language or if it is the default language
176-
* (English is the default language for CDN builds).
177-
*
178-
* Simple usage:
176+
* Simple usage (change the language of the UI and the content):
179177
*
180178
* ClassicEditor
181179
* .create( document.querySelector( '#editor' ), {
180+
* // The UI of the editor as well as its content will be in German.
182181
* language: 'de'
183182
* } )
184183
* .then( editor => {
@@ -188,14 +187,41 @@
188187
* console.error( error );
189188
* } );
190189
*
191-
* After this step you need to attach the corresponding translation file. Translation files are available on CDN for predefined builds:
190+
* Use different languages for the UI and the content using the object syntax:
191+
*
192+
* ClassicEditor
193+
* .create( document.querySelector( '#editor' ), {
194+
* language: {
195+
* // The UI will be in English.
196+
* ui: 'en',
197+
*
198+
* // But the content will be edited in Arabic.
199+
* content: 'ar'
200+
* }
201+
* } )
202+
* .then( editor => {
203+
* console.log( editor );
204+
* } )
205+
* .catch( error => {
206+
* console.error( error );
207+
* } );
208+
*
209+
* The language of the content has an impact on the editing experience, for instance it affects screen readers
210+
* and spell checkers. It is also particularly useful for typing in certain languages (e.g. right–to–left ones)
211+
* because it changes the default alignment of the text.
212+
*
213+
* The language codes are defined in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) standard.
214+
*
215+
* You need to add the corresponding translation file for the new UI language to work.
216+
* Translation files are available on CDN for predefined builds:
217+
*
192218
* `<script src="https://cdn.ckeditor.com/ckeditor5/[version.number]/[distribution]/lang/[lang].js"></script>`
193219
*
194220
* But you can add them manually by coping from the `node_modules/@ckeditor/ckeditor5-build-[name]/build/lang/[lang].js'`.
195221
*
196222
* Check the {@glink features/ui-language UI language guide} for more information about the localization options and translation process.
197223
*
198-
* @member {String} module:core/editor/editorconfig~EditorConfig#language
224+
* @member {String|Object} module:core/editor/editorconfig~EditorConfig#language
199225
*/
200226

201227
/**

tests/editor/editor.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,25 @@ describe( 'Editor', () => {
193193
expect( editor.t ).to.equal( editor.locale.t );
194194
} );
195195

196-
it( 'is configured with the config.language', () => {
196+
it( 'is configured with the config.language (UI and the content)', () => {
197197
const editor = new TestEditor( { language: 'pl' } );
198198

199-
expect( editor.locale.language ).to.equal( 'pl' );
199+
expect( editor.locale.uiLanguage ).to.equal( 'pl' );
200+
expect( editor.locale.contentLanguage ).to.equal( 'pl' );
201+
} );
202+
203+
it( 'is configured with the config.language (different for UI and the content)', () => {
204+
const editor = new TestEditor( { language: { ui: 'pl', content: 'ar' } } );
205+
206+
expect( editor.locale.uiLanguage ).to.equal( 'pl' );
207+
expect( editor.locale.contentLanguage ).to.equal( 'ar' );
208+
} );
209+
210+
it( 'is configured with the config.language (just the content)', () => {
211+
const editor = new TestEditor( { language: { content: 'ar' } } );
212+
213+
expect( editor.locale.uiLanguage ).to.equal( 'en' );
214+
expect( editor.locale.contentLanguage ).to.equal( 'ar' );
200215
} );
201216
} );
202217

0 commit comments

Comments
 (0)