@ckeditor/ckeditor5-language 39.0.1 → 40.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +3 -3
- package/build/language.js.map +1 -0
- package/lang/translations/ar.po +1 -0
- package/lang/translations/bg.po +1 -0
- package/lang/translations/bn.po +1 -0
- package/lang/translations/ca.po +1 -0
- package/lang/translations/cs.po +1 -0
- package/lang/translations/da.po +1 -0
- package/lang/translations/de-ch.po +1 -0
- package/lang/translations/de.po +1 -0
- package/lang/translations/el.po +1 -0
- package/lang/translations/en-au.po +1 -0
- package/lang/translations/en.po +1 -0
- package/lang/translations/es.po +1 -0
- package/lang/translations/et.po +1 -0
- package/lang/translations/fi.po +1 -0
- package/lang/translations/fr.po +1 -0
- package/lang/translations/gl.po +1 -0
- package/lang/translations/he.po +1 -0
- package/lang/translations/hi.po +1 -0
- package/lang/translations/hr.po +1 -0
- package/lang/translations/hu.po +1 -0
- package/lang/translations/id.po +1 -0
- package/lang/translations/it.po +1 -0
- package/lang/translations/ja.po +1 -0
- package/lang/translations/jv.po +1 -0
- package/lang/translations/ko.po +1 -0
- package/lang/translations/lt.po +1 -0
- package/lang/translations/lv.po +1 -0
- package/lang/translations/ms.po +1 -0
- package/lang/translations/nl.po +1 -0
- package/lang/translations/no.po +1 -0
- package/lang/translations/pl.po +1 -0
- package/lang/translations/pt-br.po +1 -0
- package/lang/translations/pt.po +1 -0
- package/lang/translations/ro.po +1 -0
- package/lang/translations/ru.po +1 -0
- package/lang/translations/sk.po +1 -0
- package/lang/translations/sr-latn.po +1 -0
- package/lang/translations/sr.po +1 -0
- package/lang/translations/sv.po +1 -0
- package/lang/translations/th.po +1 -0
- package/lang/translations/tk.po +1 -0
- package/lang/translations/tr.po +1 -0
- package/lang/translations/tt.po +1 -0
- package/lang/translations/ug.po +1 -0
- package/lang/translations/uk.po +1 -0
- package/lang/translations/ur.po +1 -0
- package/lang/translations/vi.po +1 -0
- package/lang/translations/zh-cn.po +1 -0
- package/lang/translations/zh.po +1 -0
- package/package.json +2 -6
- package/src/augmentation.d.ts +47 -47
- package/src/augmentation.js +5 -5
- package/src/index.d.ts +13 -13
- package/src/index.js +11 -11
- package/src/textpartlanguage.d.ts +35 -35
- package/src/textpartlanguage.js +39 -39
- package/src/textpartlanguagecommand.d.ts +70 -70
- package/src/textpartlanguagecommand.js +89 -89
- package/src/textpartlanguageconfig.d.ts +25 -25
- package/src/textpartlanguageconfig.js +5 -5
- package/src/textpartlanguageediting.d.ts +28 -28
- package/src/textpartlanguageediting.js +84 -84
- package/src/textpartlanguageui.d.ts +23 -23
- package/src/textpartlanguageui.js +101 -101
- package/src/utils.d.ts +40 -40
- package/src/utils.js +43 -43
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module language/textpartlanguageconfig
|
|
7
|
-
*/
|
|
8
|
-
import type { LanguageDirection } from 'ckeditor5/src/utils';
|
|
9
|
-
/**
|
|
10
|
-
* The text part language feature option descriptor.
|
|
11
|
-
*/
|
|
12
|
-
export interface TextPartLanguageOption {
|
|
13
|
-
/**
|
|
14
|
-
* The user-readable title of the option.
|
|
15
|
-
*/
|
|
16
|
-
title: string;
|
|
17
|
-
/**
|
|
18
|
-
* The language code in the ISO 639 format.
|
|
19
|
-
*/
|
|
20
|
-
languageCode: string;
|
|
21
|
-
/**
|
|
22
|
-
* The language text direction. Automatically detected if omitted.
|
|
23
|
-
*/
|
|
24
|
-
textDirection?: LanguageDirection;
|
|
25
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module language/textpartlanguageconfig
|
|
7
|
+
*/
|
|
8
|
+
import type { LanguageDirection } from 'ckeditor5/src/utils';
|
|
9
|
+
/**
|
|
10
|
+
* The text part language feature option descriptor.
|
|
11
|
+
*/
|
|
12
|
+
export interface TextPartLanguageOption {
|
|
13
|
+
/**
|
|
14
|
+
* The user-readable title of the option.
|
|
15
|
+
*/
|
|
16
|
+
title: string;
|
|
17
|
+
/**
|
|
18
|
+
* The language code in the ISO 639 format.
|
|
19
|
+
*/
|
|
20
|
+
languageCode: string;
|
|
21
|
+
/**
|
|
22
|
+
* The language text direction. Automatically detected if omitted.
|
|
23
|
+
*/
|
|
24
|
+
textDirection?: LanguageDirection;
|
|
25
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
export {};
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
export {};
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
6
|
-
/**
|
|
7
|
-
* The text part language editing.
|
|
8
|
-
*
|
|
9
|
-
* Introduces the `'textPartLanguage'` command and the `'language'` model element attribute.
|
|
10
|
-
*/
|
|
11
|
-
export default class TextPartLanguageEditing extends Plugin {
|
|
12
|
-
/**
|
|
13
|
-
* @inheritDoc
|
|
14
|
-
*/
|
|
15
|
-
static get pluginName(): "TextPartLanguageEditing";
|
|
16
|
-
/**
|
|
17
|
-
* @inheritDoc
|
|
18
|
-
*/
|
|
19
|
-
constructor(editor: Editor);
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
init(): void;
|
|
24
|
-
/**
|
|
25
|
-
* @private
|
|
26
|
-
*/
|
|
27
|
-
private _defineConverters;
|
|
28
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
6
|
+
/**
|
|
7
|
+
* The text part language editing.
|
|
8
|
+
*
|
|
9
|
+
* Introduces the `'textPartLanguage'` command and the `'language'` model element attribute.
|
|
10
|
+
*/
|
|
11
|
+
export default class TextPartLanguageEditing extends Plugin {
|
|
12
|
+
/**
|
|
13
|
+
* @inheritDoc
|
|
14
|
+
*/
|
|
15
|
+
static get pluginName(): "TextPartLanguageEditing";
|
|
16
|
+
/**
|
|
17
|
+
* @inheritDoc
|
|
18
|
+
*/
|
|
19
|
+
constructor(editor: Editor);
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
init(): void;
|
|
24
|
+
/**
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
private _defineConverters;
|
|
28
|
+
}
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
6
|
-
import TextPartLanguageCommand from './textpartlanguagecommand';
|
|
7
|
-
import { stringifyLanguageAttribute, parseLanguageAttribute } from './utils';
|
|
8
|
-
/**
|
|
9
|
-
* The text part language editing.
|
|
10
|
-
*
|
|
11
|
-
* Introduces the `'textPartLanguage'` command and the `'language'` model element attribute.
|
|
12
|
-
*/
|
|
13
|
-
export default class TextPartLanguageEditing extends Plugin {
|
|
14
|
-
/**
|
|
15
|
-
* @inheritDoc
|
|
16
|
-
*/
|
|
17
|
-
static get pluginName() {
|
|
18
|
-
return 'TextPartLanguageEditing';
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* @inheritDoc
|
|
22
|
-
*/
|
|
23
|
-
constructor(editor) {
|
|
24
|
-
super(editor);
|
|
25
|
-
// Text part language options are only used to ensure that the feature works by default.
|
|
26
|
-
// In the real usage it should be reconfigured by a developer. We are not providing
|
|
27
|
-
// translations for `title` properties on purpose, as it's only an example configuration.
|
|
28
|
-
editor.config.define('language', {
|
|
29
|
-
textPartLanguage: [
|
|
30
|
-
{ title: 'Arabic', languageCode: 'ar' },
|
|
31
|
-
{ title: 'French', languageCode: 'fr' },
|
|
32
|
-
{ title: 'Spanish', languageCode: 'es' }
|
|
33
|
-
]
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @inheritDoc
|
|
38
|
-
*/
|
|
39
|
-
init() {
|
|
40
|
-
const editor = this.editor;
|
|
41
|
-
editor.model.schema.extend('$text', { allowAttributes: 'language' });
|
|
42
|
-
editor.model.schema.setAttributeProperties('language', {
|
|
43
|
-
copyOnEnter: true
|
|
44
|
-
});
|
|
45
|
-
this._defineConverters();
|
|
46
|
-
editor.commands.add('textPartLanguage', new TextPartLanguageCommand(editor));
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* @private
|
|
50
|
-
*/
|
|
51
|
-
_defineConverters() {
|
|
52
|
-
const conversion = this.editor.conversion;
|
|
53
|
-
conversion.for('upcast').elementToAttribute({
|
|
54
|
-
model: {
|
|
55
|
-
key: 'language',
|
|
56
|
-
value: (viewElement) => {
|
|
57
|
-
const languageCode = viewElement.getAttribute('lang');
|
|
58
|
-
const textDirection = viewElement.getAttribute('dir');
|
|
59
|
-
return stringifyLanguageAttribute(languageCode, textDirection);
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
view: {
|
|
63
|
-
name: 'span',
|
|
64
|
-
attributes: { lang: /[\s\S]+/ }
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
conversion.for('downcast').attributeToElement({
|
|
68
|
-
model: 'language',
|
|
69
|
-
view: (attributeValue, { writer }, data) => {
|
|
70
|
-
if (!attributeValue) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (!data.item.is('$textProxy') && !data.item.is('documentSelection')) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const { languageCode, textDirection } = parseLanguageAttribute(attributeValue);
|
|
77
|
-
return writer.createAttributeElement('span', {
|
|
78
|
-
lang: languageCode,
|
|
79
|
-
dir: textDirection
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
6
|
+
import TextPartLanguageCommand from './textpartlanguagecommand';
|
|
7
|
+
import { stringifyLanguageAttribute, parseLanguageAttribute } from './utils';
|
|
8
|
+
/**
|
|
9
|
+
* The text part language editing.
|
|
10
|
+
*
|
|
11
|
+
* Introduces the `'textPartLanguage'` command and the `'language'` model element attribute.
|
|
12
|
+
*/
|
|
13
|
+
export default class TextPartLanguageEditing extends Plugin {
|
|
14
|
+
/**
|
|
15
|
+
* @inheritDoc
|
|
16
|
+
*/
|
|
17
|
+
static get pluginName() {
|
|
18
|
+
return 'TextPartLanguageEditing';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* @inheritDoc
|
|
22
|
+
*/
|
|
23
|
+
constructor(editor) {
|
|
24
|
+
super(editor);
|
|
25
|
+
// Text part language options are only used to ensure that the feature works by default.
|
|
26
|
+
// In the real usage it should be reconfigured by a developer. We are not providing
|
|
27
|
+
// translations for `title` properties on purpose, as it's only an example configuration.
|
|
28
|
+
editor.config.define('language', {
|
|
29
|
+
textPartLanguage: [
|
|
30
|
+
{ title: 'Arabic', languageCode: 'ar' },
|
|
31
|
+
{ title: 'French', languageCode: 'fr' },
|
|
32
|
+
{ title: 'Spanish', languageCode: 'es' }
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @inheritDoc
|
|
38
|
+
*/
|
|
39
|
+
init() {
|
|
40
|
+
const editor = this.editor;
|
|
41
|
+
editor.model.schema.extend('$text', { allowAttributes: 'language' });
|
|
42
|
+
editor.model.schema.setAttributeProperties('language', {
|
|
43
|
+
copyOnEnter: true
|
|
44
|
+
});
|
|
45
|
+
this._defineConverters();
|
|
46
|
+
editor.commands.add('textPartLanguage', new TextPartLanguageCommand(editor));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
_defineConverters() {
|
|
52
|
+
const conversion = this.editor.conversion;
|
|
53
|
+
conversion.for('upcast').elementToAttribute({
|
|
54
|
+
model: {
|
|
55
|
+
key: 'language',
|
|
56
|
+
value: (viewElement) => {
|
|
57
|
+
const languageCode = viewElement.getAttribute('lang');
|
|
58
|
+
const textDirection = viewElement.getAttribute('dir');
|
|
59
|
+
return stringifyLanguageAttribute(languageCode, textDirection);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
view: {
|
|
63
|
+
name: 'span',
|
|
64
|
+
attributes: { lang: /[\s\S]+/ }
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
conversion.for('downcast').attributeToElement({
|
|
68
|
+
model: 'language',
|
|
69
|
+
view: (attributeValue, { writer }, data) => {
|
|
70
|
+
if (!attributeValue) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!data.item.is('$textProxy') && !data.item.is('documentSelection')) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const { languageCode, textDirection } = parseLanguageAttribute(attributeValue);
|
|
77
|
+
return writer.createAttributeElement('span', {
|
|
78
|
+
lang: languageCode,
|
|
79
|
+
dir: textDirection
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module language/textpartlanguageui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
/**
|
|
10
|
-
* The text part language UI plugin.
|
|
11
|
-
*
|
|
12
|
-
* It introduces the `'language'` dropdown.
|
|
13
|
-
*/
|
|
14
|
-
export default class TextPartLanguageUI extends Plugin {
|
|
15
|
-
/**
|
|
16
|
-
* @inheritDoc
|
|
17
|
-
*/
|
|
18
|
-
static get pluginName(): "TextPartLanguageUI";
|
|
19
|
-
/**
|
|
20
|
-
* @inheritDoc
|
|
21
|
-
*/
|
|
22
|
-
init(): void;
|
|
23
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module language/textpartlanguageui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
/**
|
|
10
|
+
* The text part language UI plugin.
|
|
11
|
+
*
|
|
12
|
+
* It introduces the `'language'` dropdown.
|
|
13
|
+
*/
|
|
14
|
+
export default class TextPartLanguageUI extends Plugin {
|
|
15
|
+
/**
|
|
16
|
+
* @inheritDoc
|
|
17
|
+
*/
|
|
18
|
+
static get pluginName(): "TextPartLanguageUI";
|
|
19
|
+
/**
|
|
20
|
+
* @inheritDoc
|
|
21
|
+
*/
|
|
22
|
+
init(): void;
|
|
23
|
+
}
|
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module language/textpartlanguageui
|
|
7
|
-
*/
|
|
8
|
-
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
-
import { Model, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
|
|
10
|
-
import { Collection } from 'ckeditor5/src/utils';
|
|
11
|
-
import { stringifyLanguageAttribute } from './utils';
|
|
12
|
-
/**
|
|
13
|
-
* The text part language UI plugin.
|
|
14
|
-
*
|
|
15
|
-
* It introduces the `'language'` dropdown.
|
|
16
|
-
*/
|
|
17
|
-
export default class TextPartLanguageUI extends Plugin {
|
|
18
|
-
/**
|
|
19
|
-
* @inheritDoc
|
|
20
|
-
*/
|
|
21
|
-
static get pluginName() {
|
|
22
|
-
return 'TextPartLanguageUI';
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* @inheritDoc
|
|
26
|
-
*/
|
|
27
|
-
init() {
|
|
28
|
-
const editor = this.editor;
|
|
29
|
-
const t = editor.t;
|
|
30
|
-
const options = editor.config.get('language.textPartLanguage');
|
|
31
|
-
const defaultTitle = t('Choose language');
|
|
32
|
-
const removeTitle = t('Remove language');
|
|
33
|
-
const accessibleLabel = t('Language');
|
|
34
|
-
// Register UI component.
|
|
35
|
-
editor.ui.componentFactory.add('textPartLanguage', locale => {
|
|
36
|
-
const itemDefinitions = new Collection();
|
|
37
|
-
const titles = {};
|
|
38
|
-
const languageCommand = editor.commands.get('textPartLanguage');
|
|
39
|
-
// Item definition with false `languageCode` will behave as remove lang button.
|
|
40
|
-
itemDefinitions.add({
|
|
41
|
-
type: 'button',
|
|
42
|
-
model: new Model({
|
|
43
|
-
label: removeTitle,
|
|
44
|
-
languageCode: false,
|
|
45
|
-
withText: true
|
|
46
|
-
})
|
|
47
|
-
});
|
|
48
|
-
itemDefinitions.add({
|
|
49
|
-
type: 'separator'
|
|
50
|
-
});
|
|
51
|
-
for (const option of options) {
|
|
52
|
-
const def = {
|
|
53
|
-
type: 'button',
|
|
54
|
-
model: new Model({
|
|
55
|
-
label: option.title,
|
|
56
|
-
languageCode: option.languageCode,
|
|
57
|
-
role: 'menuitemradio',
|
|
58
|
-
textDirection: option.textDirection,
|
|
59
|
-
withText: true
|
|
60
|
-
})
|
|
61
|
-
};
|
|
62
|
-
const language = stringifyLanguageAttribute(option.languageCode, option.textDirection);
|
|
63
|
-
def.model.bind('isOn').to(languageCommand, 'value', value => value === language);
|
|
64
|
-
itemDefinitions.add(def);
|
|
65
|
-
titles[language] = option.title;
|
|
66
|
-
}
|
|
67
|
-
const dropdownView = createDropdown(locale);
|
|
68
|
-
addListToDropdown(dropdownView, itemDefinitions, {
|
|
69
|
-
ariaLabel: accessibleLabel,
|
|
70
|
-
role: 'menu'
|
|
71
|
-
});
|
|
72
|
-
dropdownView.buttonView.set({
|
|
73
|
-
ariaLabel: accessibleLabel,
|
|
74
|
-
ariaLabelledBy: undefined,
|
|
75
|
-
isOn: false,
|
|
76
|
-
withText: true,
|
|
77
|
-
tooltip: accessibleLabel
|
|
78
|
-
});
|
|
79
|
-
dropdownView.extendTemplate({
|
|
80
|
-
attributes: {
|
|
81
|
-
class: [
|
|
82
|
-
'ck-text-fragment-language-dropdown'
|
|
83
|
-
]
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
dropdownView.bind('isEnabled').to(languageCommand, 'isEnabled');
|
|
87
|
-
dropdownView.buttonView.bind('label').to(languageCommand, 'value', value => {
|
|
88
|
-
return (value && titles[value]) || defaultTitle;
|
|
89
|
-
});
|
|
90
|
-
// Execute command when an item from the dropdown is selected.
|
|
91
|
-
this.listenTo(dropdownView, 'execute', evt => {
|
|
92
|
-
languageCommand.execute({
|
|
93
|
-
languageCode: evt.source.languageCode,
|
|
94
|
-
textDirection: evt.source.textDirection
|
|
95
|
-
});
|
|
96
|
-
editor.editing.view.focus();
|
|
97
|
-
});
|
|
98
|
-
return dropdownView;
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module language/textpartlanguageui
|
|
7
|
+
*/
|
|
8
|
+
import { Plugin } from 'ckeditor5/src/core';
|
|
9
|
+
import { Model, createDropdown, addListToDropdown } from 'ckeditor5/src/ui';
|
|
10
|
+
import { Collection } from 'ckeditor5/src/utils';
|
|
11
|
+
import { stringifyLanguageAttribute } from './utils';
|
|
12
|
+
/**
|
|
13
|
+
* The text part language UI plugin.
|
|
14
|
+
*
|
|
15
|
+
* It introduces the `'language'` dropdown.
|
|
16
|
+
*/
|
|
17
|
+
export default class TextPartLanguageUI extends Plugin {
|
|
18
|
+
/**
|
|
19
|
+
* @inheritDoc
|
|
20
|
+
*/
|
|
21
|
+
static get pluginName() {
|
|
22
|
+
return 'TextPartLanguageUI';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @inheritDoc
|
|
26
|
+
*/
|
|
27
|
+
init() {
|
|
28
|
+
const editor = this.editor;
|
|
29
|
+
const t = editor.t;
|
|
30
|
+
const options = editor.config.get('language.textPartLanguage');
|
|
31
|
+
const defaultTitle = t('Choose language');
|
|
32
|
+
const removeTitle = t('Remove language');
|
|
33
|
+
const accessibleLabel = t('Language');
|
|
34
|
+
// Register UI component.
|
|
35
|
+
editor.ui.componentFactory.add('textPartLanguage', locale => {
|
|
36
|
+
const itemDefinitions = new Collection();
|
|
37
|
+
const titles = {};
|
|
38
|
+
const languageCommand = editor.commands.get('textPartLanguage');
|
|
39
|
+
// Item definition with false `languageCode` will behave as remove lang button.
|
|
40
|
+
itemDefinitions.add({
|
|
41
|
+
type: 'button',
|
|
42
|
+
model: new Model({
|
|
43
|
+
label: removeTitle,
|
|
44
|
+
languageCode: false,
|
|
45
|
+
withText: true
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
itemDefinitions.add({
|
|
49
|
+
type: 'separator'
|
|
50
|
+
});
|
|
51
|
+
for (const option of options) {
|
|
52
|
+
const def = {
|
|
53
|
+
type: 'button',
|
|
54
|
+
model: new Model({
|
|
55
|
+
label: option.title,
|
|
56
|
+
languageCode: option.languageCode,
|
|
57
|
+
role: 'menuitemradio',
|
|
58
|
+
textDirection: option.textDirection,
|
|
59
|
+
withText: true
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
const language = stringifyLanguageAttribute(option.languageCode, option.textDirection);
|
|
63
|
+
def.model.bind('isOn').to(languageCommand, 'value', value => value === language);
|
|
64
|
+
itemDefinitions.add(def);
|
|
65
|
+
titles[language] = option.title;
|
|
66
|
+
}
|
|
67
|
+
const dropdownView = createDropdown(locale);
|
|
68
|
+
addListToDropdown(dropdownView, itemDefinitions, {
|
|
69
|
+
ariaLabel: accessibleLabel,
|
|
70
|
+
role: 'menu'
|
|
71
|
+
});
|
|
72
|
+
dropdownView.buttonView.set({
|
|
73
|
+
ariaLabel: accessibleLabel,
|
|
74
|
+
ariaLabelledBy: undefined,
|
|
75
|
+
isOn: false,
|
|
76
|
+
withText: true,
|
|
77
|
+
tooltip: accessibleLabel
|
|
78
|
+
});
|
|
79
|
+
dropdownView.extendTemplate({
|
|
80
|
+
attributes: {
|
|
81
|
+
class: [
|
|
82
|
+
'ck-text-fragment-language-dropdown'
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
dropdownView.bind('isEnabled').to(languageCommand, 'isEnabled');
|
|
87
|
+
dropdownView.buttonView.bind('label').to(languageCommand, 'value', value => {
|
|
88
|
+
return (value && titles[value]) || defaultTitle;
|
|
89
|
+
});
|
|
90
|
+
// Execute command when an item from the dropdown is selected.
|
|
91
|
+
this.listenTo(dropdownView, 'execute', evt => {
|
|
92
|
+
languageCommand.execute({
|
|
93
|
+
languageCode: evt.source.languageCode,
|
|
94
|
+
textDirection: evt.source.textDirection
|
|
95
|
+
});
|
|
96
|
+
editor.editing.view.focus();
|
|
97
|
+
});
|
|
98
|
+
return dropdownView;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
package/src/utils.d.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
-
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @module language/utils
|
|
7
|
-
*/
|
|
8
|
-
import { type LanguageDirection } from 'ckeditor5/src/utils';
|
|
9
|
-
/**
|
|
10
|
-
* Returns the language attribute value in a human-readable text format:
|
|
11
|
-
*
|
|
12
|
-
* ```
|
|
13
|
-
* <languageCode>:<textDirection>
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* * `languageCode` - The language code used for the `lang` attribute in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
|
|
17
|
-
* * `textDirection` - One of the following values: `rtl` or `ltr`, indicating the reading direction of the language.
|
|
18
|
-
*
|
|
19
|
-
* See the {@link module:core/editor/editorconfig~LanguageConfig#textPartLanguage text part language configuration}
|
|
20
|
-
* for more information about language properties.
|
|
21
|
-
*
|
|
22
|
-
* If the `textDirection` argument is omitted, it will be automatically detected based on `languageCode`.
|
|
23
|
-
*
|
|
24
|
-
* @param languageCode The language code in the ISO 639-1 format.
|
|
25
|
-
* @param textDirection The language text direction. Automatically detected if omitted.
|
|
26
|
-
*/
|
|
27
|
-
export declare function stringifyLanguageAttribute(languageCode: string, textDirection?: LanguageDirection): string;
|
|
28
|
-
/**
|
|
29
|
-
* Retrieves language properties converted to attribute value by the
|
|
30
|
-
* {@link module:language/utils~stringifyLanguageAttribute stringifyLanguageAttribute} function.
|
|
31
|
-
*
|
|
32
|
-
* @param str The attribute value.
|
|
33
|
-
* @returns The object with properties:
|
|
34
|
-
* * languageCode - The language code in the ISO 639 format.
|
|
35
|
-
* * textDirection - The language text direction.
|
|
36
|
-
*/
|
|
37
|
-
export declare function parseLanguageAttribute(str: string): {
|
|
38
|
-
languageCode: string;
|
|
39
|
-
textDirection: string;
|
|
40
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
|
+
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @module language/utils
|
|
7
|
+
*/
|
|
8
|
+
import { type LanguageDirection } from 'ckeditor5/src/utils';
|
|
9
|
+
/**
|
|
10
|
+
* Returns the language attribute value in a human-readable text format:
|
|
11
|
+
*
|
|
12
|
+
* ```
|
|
13
|
+
* <languageCode>:<textDirection>
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* * `languageCode` - The language code used for the `lang` attribute in the [ISO 639-1](https://en.wikipedia.org/wiki/ISO_639-1) format.
|
|
17
|
+
* * `textDirection` - One of the following values: `rtl` or `ltr`, indicating the reading direction of the language.
|
|
18
|
+
*
|
|
19
|
+
* See the {@link module:core/editor/editorconfig~LanguageConfig#textPartLanguage text part language configuration}
|
|
20
|
+
* for more information about language properties.
|
|
21
|
+
*
|
|
22
|
+
* If the `textDirection` argument is omitted, it will be automatically detected based on `languageCode`.
|
|
23
|
+
*
|
|
24
|
+
* @param languageCode The language code in the ISO 639-1 format.
|
|
25
|
+
* @param textDirection The language text direction. Automatically detected if omitted.
|
|
26
|
+
*/
|
|
27
|
+
export declare function stringifyLanguageAttribute(languageCode: string, textDirection?: LanguageDirection): string;
|
|
28
|
+
/**
|
|
29
|
+
* Retrieves language properties converted to attribute value by the
|
|
30
|
+
* {@link module:language/utils~stringifyLanguageAttribute stringifyLanguageAttribute} function.
|
|
31
|
+
*
|
|
32
|
+
* @param str The attribute value.
|
|
33
|
+
* @returns The object with properties:
|
|
34
|
+
* * languageCode - The language code in the ISO 639 format.
|
|
35
|
+
* * textDirection - The language text direction.
|
|
36
|
+
*/
|
|
37
|
+
export declare function parseLanguageAttribute(str: string): {
|
|
38
|
+
languageCode: string;
|
|
39
|
+
textDirection: string;
|
|
40
|
+
};
|