@ckeditor/ckeditor5-language 0.0.0-internal-20241017.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.
Files changed (280) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/LICENSE.md +17 -0
  3. package/README.md +26 -0
  4. package/build/language.js +5 -0
  5. package/build/translations/ar.js +1 -0
  6. package/build/translations/bg.js +1 -0
  7. package/build/translations/bn.js +1 -0
  8. package/build/translations/ca.js +1 -0
  9. package/build/translations/cs.js +1 -0
  10. package/build/translations/da.js +1 -0
  11. package/build/translations/de-ch.js +1 -0
  12. package/build/translations/de.js +1 -0
  13. package/build/translations/el.js +1 -0
  14. package/build/translations/en-au.js +1 -0
  15. package/build/translations/es.js +1 -0
  16. package/build/translations/et.js +1 -0
  17. package/build/translations/fi.js +1 -0
  18. package/build/translations/fr.js +1 -0
  19. package/build/translations/gl.js +1 -0
  20. package/build/translations/he.js +1 -0
  21. package/build/translations/hi.js +1 -0
  22. package/build/translations/hr.js +1 -0
  23. package/build/translations/hu.js +1 -0
  24. package/build/translations/id.js +1 -0
  25. package/build/translations/it.js +1 -0
  26. package/build/translations/ja.js +1 -0
  27. package/build/translations/jv.js +1 -0
  28. package/build/translations/ko.js +1 -0
  29. package/build/translations/lt.js +1 -0
  30. package/build/translations/lv.js +1 -0
  31. package/build/translations/ms.js +1 -0
  32. package/build/translations/nl.js +1 -0
  33. package/build/translations/no.js +1 -0
  34. package/build/translations/pl.js +1 -0
  35. package/build/translations/pt-br.js +1 -0
  36. package/build/translations/pt.js +1 -0
  37. package/build/translations/ro.js +1 -0
  38. package/build/translations/ru.js +1 -0
  39. package/build/translations/sk.js +1 -0
  40. package/build/translations/sr-latn.js +1 -0
  41. package/build/translations/sr.js +1 -0
  42. package/build/translations/sv.js +1 -0
  43. package/build/translations/th.js +1 -0
  44. package/build/translations/tk.js +1 -0
  45. package/build/translations/tr.js +1 -0
  46. package/build/translations/tt.js +1 -0
  47. package/build/translations/ug.js +1 -0
  48. package/build/translations/uk.js +1 -0
  49. package/build/translations/ur.js +1 -0
  50. package/build/translations/vi.js +1 -0
  51. package/build/translations/zh-cn.js +1 -0
  52. package/build/translations/zh.js +1 -0
  53. package/ckeditor5-metadata.json +27 -0
  54. package/dist/augmentation.d.ts +51 -0
  55. package/dist/index-content.css +4 -0
  56. package/dist/index-editor.css +4 -0
  57. package/dist/index.css +4 -0
  58. package/dist/index.d.ts +17 -0
  59. package/dist/index.js +402 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/textpartlanguage.d.ts +43 -0
  62. package/dist/textpartlanguagecommand.d.ts +74 -0
  63. package/dist/textpartlanguageconfig.d.ts +29 -0
  64. package/dist/textpartlanguageediting.d.ts +36 -0
  65. package/dist/textpartlanguageui.d.ts +35 -0
  66. package/dist/translations/ar.d.ts +8 -0
  67. package/dist/translations/ar.js +5 -0
  68. package/dist/translations/ar.umd.js +11 -0
  69. package/dist/translations/bg.d.ts +8 -0
  70. package/dist/translations/bg.js +5 -0
  71. package/dist/translations/bg.umd.js +11 -0
  72. package/dist/translations/bn.d.ts +8 -0
  73. package/dist/translations/bn.js +5 -0
  74. package/dist/translations/bn.umd.js +11 -0
  75. package/dist/translations/ca.d.ts +8 -0
  76. package/dist/translations/ca.js +5 -0
  77. package/dist/translations/ca.umd.js +11 -0
  78. package/dist/translations/cs.d.ts +8 -0
  79. package/dist/translations/cs.js +5 -0
  80. package/dist/translations/cs.umd.js +11 -0
  81. package/dist/translations/da.d.ts +8 -0
  82. package/dist/translations/da.js +5 -0
  83. package/dist/translations/da.umd.js +11 -0
  84. package/dist/translations/de-ch.d.ts +8 -0
  85. package/dist/translations/de-ch.js +5 -0
  86. package/dist/translations/de-ch.umd.js +11 -0
  87. package/dist/translations/de.d.ts +8 -0
  88. package/dist/translations/de.js +5 -0
  89. package/dist/translations/de.umd.js +11 -0
  90. package/dist/translations/el.d.ts +8 -0
  91. package/dist/translations/el.js +5 -0
  92. package/dist/translations/el.umd.js +11 -0
  93. package/dist/translations/en-au.d.ts +8 -0
  94. package/dist/translations/en-au.js +5 -0
  95. package/dist/translations/en-au.umd.js +11 -0
  96. package/dist/translations/en.d.ts +8 -0
  97. package/dist/translations/en.js +5 -0
  98. package/dist/translations/en.umd.js +11 -0
  99. package/dist/translations/es.d.ts +8 -0
  100. package/dist/translations/es.js +5 -0
  101. package/dist/translations/es.umd.js +11 -0
  102. package/dist/translations/et.d.ts +8 -0
  103. package/dist/translations/et.js +5 -0
  104. package/dist/translations/et.umd.js +11 -0
  105. package/dist/translations/fi.d.ts +8 -0
  106. package/dist/translations/fi.js +5 -0
  107. package/dist/translations/fi.umd.js +11 -0
  108. package/dist/translations/fr.d.ts +8 -0
  109. package/dist/translations/fr.js +5 -0
  110. package/dist/translations/fr.umd.js +11 -0
  111. package/dist/translations/gl.d.ts +8 -0
  112. package/dist/translations/gl.js +5 -0
  113. package/dist/translations/gl.umd.js +11 -0
  114. package/dist/translations/he.d.ts +8 -0
  115. package/dist/translations/he.js +5 -0
  116. package/dist/translations/he.umd.js +11 -0
  117. package/dist/translations/hi.d.ts +8 -0
  118. package/dist/translations/hi.js +5 -0
  119. package/dist/translations/hi.umd.js +11 -0
  120. package/dist/translations/hr.d.ts +8 -0
  121. package/dist/translations/hr.js +5 -0
  122. package/dist/translations/hr.umd.js +11 -0
  123. package/dist/translations/hu.d.ts +8 -0
  124. package/dist/translations/hu.js +5 -0
  125. package/dist/translations/hu.umd.js +11 -0
  126. package/dist/translations/id.d.ts +8 -0
  127. package/dist/translations/id.js +5 -0
  128. package/dist/translations/id.umd.js +11 -0
  129. package/dist/translations/it.d.ts +8 -0
  130. package/dist/translations/it.js +5 -0
  131. package/dist/translations/it.umd.js +11 -0
  132. package/dist/translations/ja.d.ts +8 -0
  133. package/dist/translations/ja.js +5 -0
  134. package/dist/translations/ja.umd.js +11 -0
  135. package/dist/translations/jv.d.ts +8 -0
  136. package/dist/translations/jv.js +5 -0
  137. package/dist/translations/jv.umd.js +11 -0
  138. package/dist/translations/ko.d.ts +8 -0
  139. package/dist/translations/ko.js +5 -0
  140. package/dist/translations/ko.umd.js +11 -0
  141. package/dist/translations/lt.d.ts +8 -0
  142. package/dist/translations/lt.js +5 -0
  143. package/dist/translations/lt.umd.js +11 -0
  144. package/dist/translations/lv.d.ts +8 -0
  145. package/dist/translations/lv.js +5 -0
  146. package/dist/translations/lv.umd.js +11 -0
  147. package/dist/translations/ms.d.ts +8 -0
  148. package/dist/translations/ms.js +5 -0
  149. package/dist/translations/ms.umd.js +11 -0
  150. package/dist/translations/nl.d.ts +8 -0
  151. package/dist/translations/nl.js +5 -0
  152. package/dist/translations/nl.umd.js +11 -0
  153. package/dist/translations/no.d.ts +8 -0
  154. package/dist/translations/no.js +5 -0
  155. package/dist/translations/no.umd.js +11 -0
  156. package/dist/translations/pl.d.ts +8 -0
  157. package/dist/translations/pl.js +5 -0
  158. package/dist/translations/pl.umd.js +11 -0
  159. package/dist/translations/pt-br.d.ts +8 -0
  160. package/dist/translations/pt-br.js +5 -0
  161. package/dist/translations/pt-br.umd.js +11 -0
  162. package/dist/translations/pt.d.ts +8 -0
  163. package/dist/translations/pt.js +5 -0
  164. package/dist/translations/pt.umd.js +11 -0
  165. package/dist/translations/ro.d.ts +8 -0
  166. package/dist/translations/ro.js +5 -0
  167. package/dist/translations/ro.umd.js +11 -0
  168. package/dist/translations/ru.d.ts +8 -0
  169. package/dist/translations/ru.js +5 -0
  170. package/dist/translations/ru.umd.js +11 -0
  171. package/dist/translations/sk.d.ts +8 -0
  172. package/dist/translations/sk.js +5 -0
  173. package/dist/translations/sk.umd.js +11 -0
  174. package/dist/translations/sr-latn.d.ts +8 -0
  175. package/dist/translations/sr-latn.js +5 -0
  176. package/dist/translations/sr-latn.umd.js +11 -0
  177. package/dist/translations/sr.d.ts +8 -0
  178. package/dist/translations/sr.js +5 -0
  179. package/dist/translations/sr.umd.js +11 -0
  180. package/dist/translations/sv.d.ts +8 -0
  181. package/dist/translations/sv.js +5 -0
  182. package/dist/translations/sv.umd.js +11 -0
  183. package/dist/translations/th.d.ts +8 -0
  184. package/dist/translations/th.js +5 -0
  185. package/dist/translations/th.umd.js +11 -0
  186. package/dist/translations/tk.d.ts +8 -0
  187. package/dist/translations/tk.js +5 -0
  188. package/dist/translations/tk.umd.js +11 -0
  189. package/dist/translations/tr.d.ts +8 -0
  190. package/dist/translations/tr.js +5 -0
  191. package/dist/translations/tr.umd.js +11 -0
  192. package/dist/translations/tt.d.ts +8 -0
  193. package/dist/translations/tt.js +5 -0
  194. package/dist/translations/tt.umd.js +11 -0
  195. package/dist/translations/ug.d.ts +8 -0
  196. package/dist/translations/ug.js +5 -0
  197. package/dist/translations/ug.umd.js +11 -0
  198. package/dist/translations/uk.d.ts +8 -0
  199. package/dist/translations/uk.js +5 -0
  200. package/dist/translations/uk.umd.js +11 -0
  201. package/dist/translations/ur.d.ts +8 -0
  202. package/dist/translations/ur.js +5 -0
  203. package/dist/translations/ur.umd.js +11 -0
  204. package/dist/translations/vi.d.ts +8 -0
  205. package/dist/translations/vi.js +5 -0
  206. package/dist/translations/vi.umd.js +11 -0
  207. package/dist/translations/zh-cn.d.ts +8 -0
  208. package/dist/translations/zh-cn.js +5 -0
  209. package/dist/translations/zh-cn.umd.js +11 -0
  210. package/dist/translations/zh.d.ts +8 -0
  211. package/dist/translations/zh.js +5 -0
  212. package/dist/translations/zh.umd.js +11 -0
  213. package/dist/utils.d.ts +44 -0
  214. package/lang/contexts.json +5 -0
  215. package/lang/translations/ar.po +30 -0
  216. package/lang/translations/bg.po +30 -0
  217. package/lang/translations/bn.po +30 -0
  218. package/lang/translations/ca.po +30 -0
  219. package/lang/translations/cs.po +30 -0
  220. package/lang/translations/da.po +30 -0
  221. package/lang/translations/de-ch.po +30 -0
  222. package/lang/translations/de.po +30 -0
  223. package/lang/translations/el.po +30 -0
  224. package/lang/translations/en-au.po +30 -0
  225. package/lang/translations/en.po +30 -0
  226. package/lang/translations/es.po +30 -0
  227. package/lang/translations/et.po +30 -0
  228. package/lang/translations/fi.po +30 -0
  229. package/lang/translations/fr.po +30 -0
  230. package/lang/translations/gl.po +30 -0
  231. package/lang/translations/he.po +30 -0
  232. package/lang/translations/hi.po +30 -0
  233. package/lang/translations/hr.po +30 -0
  234. package/lang/translations/hu.po +30 -0
  235. package/lang/translations/id.po +30 -0
  236. package/lang/translations/it.po +30 -0
  237. package/lang/translations/ja.po +30 -0
  238. package/lang/translations/jv.po +30 -0
  239. package/lang/translations/ko.po +30 -0
  240. package/lang/translations/lt.po +30 -0
  241. package/lang/translations/lv.po +30 -0
  242. package/lang/translations/ms.po +30 -0
  243. package/lang/translations/nl.po +30 -0
  244. package/lang/translations/no.po +30 -0
  245. package/lang/translations/pl.po +30 -0
  246. package/lang/translations/pt-br.po +30 -0
  247. package/lang/translations/pt.po +30 -0
  248. package/lang/translations/ro.po +30 -0
  249. package/lang/translations/ru.po +30 -0
  250. package/lang/translations/sk.po +30 -0
  251. package/lang/translations/sr-latn.po +30 -0
  252. package/lang/translations/sr.po +30 -0
  253. package/lang/translations/sv.po +30 -0
  254. package/lang/translations/th.po +30 -0
  255. package/lang/translations/tk.po +30 -0
  256. package/lang/translations/tr.po +30 -0
  257. package/lang/translations/tt.po +30 -0
  258. package/lang/translations/ug.po +30 -0
  259. package/lang/translations/uk.po +30 -0
  260. package/lang/translations/ur.po +30 -0
  261. package/lang/translations/vi.po +30 -0
  262. package/lang/translations/zh-cn.po +30 -0
  263. package/lang/translations/zh.po +30 -0
  264. package/package.json +41 -0
  265. package/src/augmentation.d.ts +47 -0
  266. package/src/augmentation.js +5 -0
  267. package/src/index.d.ts +13 -0
  268. package/src/index.js +11 -0
  269. package/src/textpartlanguage.d.ts +39 -0
  270. package/src/textpartlanguage.js +45 -0
  271. package/src/textpartlanguagecommand.d.ts +70 -0
  272. package/src/textpartlanguagecommand.js +89 -0
  273. package/src/textpartlanguageconfig.d.ts +25 -0
  274. package/src/textpartlanguageconfig.js +5 -0
  275. package/src/textpartlanguageediting.d.ts +32 -0
  276. package/src/textpartlanguageediting.js +90 -0
  277. package/src/textpartlanguageui.d.ts +31 -0
  278. package/src/textpartlanguageui.js +167 -0
  279. package/src/utils.d.ts +40 -0
  280. package/src/utils.js +43 -0
@@ -0,0 +1,167 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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.js';
9
+ import { addListToDropdown, createDropdown, ListSeparatorView, MenuBarMenuView, MenuBarMenuListView, MenuBarMenuListItemView, MenuBarMenuListItemButtonView, ViewModel } from 'ckeditor5/src/ui.js';
10
+ import { Collection } from 'ckeditor5/src/utils.js';
11
+ import { stringifyLanguageAttribute } from './utils.js';
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
+ static get isOfficialPlugin() {
28
+ return true;
29
+ }
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ init() {
34
+ const editor = this.editor;
35
+ const t = editor.t;
36
+ const defaultTitle = t('Choose language');
37
+ const accessibleLabel = t('Language');
38
+ // Register UI component.
39
+ editor.ui.componentFactory.add('textPartLanguage', locale => {
40
+ const { definitions, titles } = this._getItemMetadata();
41
+ const languageCommand = editor.commands.get('textPartLanguage');
42
+ const dropdownView = createDropdown(locale);
43
+ addListToDropdown(dropdownView, definitions, {
44
+ ariaLabel: accessibleLabel,
45
+ role: 'menu'
46
+ });
47
+ dropdownView.buttonView.set({
48
+ ariaLabel: accessibleLabel,
49
+ ariaLabelledBy: undefined,
50
+ isOn: false,
51
+ withText: true,
52
+ tooltip: accessibleLabel
53
+ });
54
+ dropdownView.extendTemplate({
55
+ attributes: {
56
+ class: [
57
+ 'ck-text-fragment-language-dropdown'
58
+ ]
59
+ }
60
+ });
61
+ dropdownView.bind('isEnabled').to(languageCommand, 'isEnabled');
62
+ dropdownView.buttonView.bind('label').to(languageCommand, 'value', value => {
63
+ return (value && titles[value]) || defaultTitle;
64
+ });
65
+ dropdownView.buttonView.bind('ariaLabel').to(languageCommand, 'value', value => {
66
+ const selectedLanguageTitle = value && titles[value];
67
+ if (!selectedLanguageTitle) {
68
+ return accessibleLabel;
69
+ }
70
+ return `${selectedLanguageTitle}, ${accessibleLabel}`;
71
+ });
72
+ // Execute command when an item from the dropdown is selected.
73
+ this.listenTo(dropdownView, 'execute', evt => {
74
+ languageCommand.execute({
75
+ languageCode: evt.source.languageCode,
76
+ textDirection: evt.source.textDirection
77
+ });
78
+ editor.editing.view.focus();
79
+ });
80
+ return dropdownView;
81
+ });
82
+ // Register menu bar UI component.
83
+ editor.ui.componentFactory.add('menuBar:textPartLanguage', locale => {
84
+ const { definitions } = this._getItemMetadata();
85
+ const languageCommand = editor.commands.get('textPartLanguage');
86
+ const menuView = new MenuBarMenuView(locale);
87
+ menuView.buttonView.set({
88
+ label: accessibleLabel
89
+ });
90
+ const listView = new MenuBarMenuListView(locale);
91
+ listView.set({
92
+ ariaLabel: t('Language'),
93
+ role: 'menu'
94
+ });
95
+ for (const definition of definitions) {
96
+ if (definition.type != 'button') {
97
+ listView.items.add(new ListSeparatorView(locale));
98
+ continue;
99
+ }
100
+ const listItemView = new MenuBarMenuListItemView(locale, menuView);
101
+ const buttonView = new MenuBarMenuListItemButtonView(locale);
102
+ buttonView.set({
103
+ role: 'menuitemradio',
104
+ isToggleable: true
105
+ });
106
+ buttonView.bind(...Object.keys(definition.model)).to(definition.model);
107
+ buttonView.delegate('execute').to(menuView);
108
+ listItemView.children.add(buttonView);
109
+ listView.items.add(listItemView);
110
+ }
111
+ menuView.bind('isEnabled').to(languageCommand, 'isEnabled');
112
+ menuView.panelView.children.add(listView);
113
+ menuView.on('execute', evt => {
114
+ languageCommand.execute({
115
+ languageCode: evt.source.languageCode,
116
+ textDirection: evt.source.textDirection
117
+ });
118
+ editor.editing.view.focus();
119
+ });
120
+ return menuView;
121
+ });
122
+ }
123
+ /**
124
+ * Returns metadata for dropdown and menu items.
125
+ */
126
+ _getItemMetadata() {
127
+ const editor = this.editor;
128
+ const itemDefinitions = new Collection();
129
+ const titles = {};
130
+ const languageCommand = editor.commands.get('textPartLanguage');
131
+ const options = editor.config.get('language.textPartLanguage');
132
+ const t = editor.locale.t;
133
+ const removeTitle = t('Remove language');
134
+ // Item definition with false `languageCode` will behave as remove lang button.
135
+ itemDefinitions.add({
136
+ type: 'button',
137
+ model: new ViewModel({
138
+ label: removeTitle,
139
+ languageCode: false,
140
+ withText: true
141
+ })
142
+ });
143
+ itemDefinitions.add({
144
+ type: 'separator'
145
+ });
146
+ for (const option of options) {
147
+ const def = {
148
+ type: 'button',
149
+ model: new ViewModel({
150
+ label: option.title,
151
+ languageCode: option.languageCode,
152
+ role: 'menuitemradio',
153
+ textDirection: option.textDirection,
154
+ withText: true
155
+ })
156
+ };
157
+ const language = stringifyLanguageAttribute(option.languageCode, option.textDirection);
158
+ def.model.bind('isOn').to(languageCommand, 'value', value => value === language);
159
+ itemDefinitions.add(def);
160
+ titles[language] = option.title;
161
+ }
162
+ return {
163
+ definitions: itemDefinitions,
164
+ titles
165
+ };
166
+ }
167
+ }
package/src/utils.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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.js';
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 ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, 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.js';
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
+ }