@ckeditor/ckeditor5-language 38.0.1 → 38.1.1

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.
@@ -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
+ };
package/src/utils.js CHANGED
@@ -1,43 +1,43 @@
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 { getLanguageDirection } 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 function stringifyLanguageAttribute(languageCode, textDirection) {
28
- textDirection = textDirection || getLanguageDirection(languageCode);
29
- return `${languageCode}:${textDirection}`;
30
- }
31
- /**
32
- * Retrieves language properties converted to attribute value by the
33
- * {@link module:language/utils~stringifyLanguageAttribute stringifyLanguageAttribute} function.
34
- *
35
- * @param str The attribute value.
36
- * @returns The object with properties:
37
- * * languageCode - The language code in the ISO 639 format.
38
- * * textDirection - The language text direction.
39
- */
40
- export function parseLanguageAttribute(str) {
41
- const [languageCode, textDirection] = str.split(':');
42
- return { languageCode, textDirection };
43
- }
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 { getLanguageDirection } 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 function stringifyLanguageAttribute(languageCode, textDirection) {
28
+ textDirection = textDirection || getLanguageDirection(languageCode);
29
+ return `${languageCode}:${textDirection}`;
30
+ }
31
+ /**
32
+ * Retrieves language properties converted to attribute value by the
33
+ * {@link module:language/utils~stringifyLanguageAttribute stringifyLanguageAttribute} function.
34
+ *
35
+ * @param str The attribute value.
36
+ * @returns The object with properties:
37
+ * * languageCode - The language code in the ISO 639 format.
38
+ * * textDirection - The language text direction.
39
+ */
40
+ export function parseLanguageAttribute(str) {
41
+ const [languageCode, textDirection] = str.split(':');
42
+ return { languageCode, textDirection };
43
+ }