Skip to content

Commit 83c5bf7

Browse files
HtmlEditor: make localization working for borderStyle selectbox if messages are loaded at runtime (T1234032) (#28894)
1 parent 9c4b5b1 commit 83c5bf7

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

packages/devextreme/js/__internal/ui/html_editor/utils/m_toolbar_helper.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ import {
2525

2626
const MIN_HEIGHT = 400;
2727
const BORDER_STYLES = ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'];
28-
const BORDER_STYLES_TRANSLATED = BORDER_STYLES.map((style) => ({
29-
id: style,
30-
value: localizationMessage.format(`dxHtmlEditor-borderStyle${camelize(style, true)}`),
31-
}));
3228

3329
const USER_ACTION = 'user';
3430
const SILENT_ACTION = 'silent';
@@ -51,6 +47,13 @@ const ICON_MAP = {
5147
clear: 'clearformat',
5248
};
5349

50+
function getBorderStylesTranslated() {
51+
return BORDER_STYLES.map((style) => ({
52+
id: style,
53+
value: localizationMessage.format(`dxHtmlEditor-borderStyle${camelize(style, true)}`),
54+
}));
55+
}
56+
5457
function getFormatHandlers(module) {
5558
return {
5659
clear: ({ event }) => {
@@ -446,7 +449,7 @@ function getTablePropertiesFormConfig(module, { $element, formats, tableBlot })
446449
label: { text: localizationMessage.format('dxHtmlEditor-style') },
447450
editorType: 'dxSelectBox',
448451
editorOptions: {
449-
items: BORDER_STYLES_TRANSLATED,
452+
items: getBorderStylesTranslated(),
450453
valueExpr: 'id',
451454
displayExpr: 'value',
452455
placeholder: 'Select style',
@@ -616,7 +619,7 @@ function getCellPropertiesFormConfig(module, {
616619
label: { text: localizationMessage.format('dxHtmlEditor-style') },
617620
editorType: 'dxSelectBox',
618621
editorOptions: {
619-
items: BORDER_STYLES_TRANSLATED,
622+
items: getBorderStylesTranslated(),
620623
valueExpr: 'id',
621624
displayExpr: 'value',
622625
},

packages/devextreme/testing/tests/DevExpress.ui.widgets.htmlEditor/htmlEditorParts/tableProperties.tests.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import $ from 'jquery';
22
import 'ui/html_editor';
3+
import localization from 'localization';
34

45
import { getFormatHandlers } from '__internal/ui/html_editor/utils/m_toolbar_helper';
56

@@ -1136,4 +1137,34 @@ module('Table properties forms', {
11361137
});
11371138
});
11381139

1140+
module('Localization', {
1141+
beforeEach: function() {
1142+
this.messages = {
1143+
'de': {
1144+
'dxHtmlEditor-borderStyleNone': 'Test',
1145+
}
1146+
};
1147+
localization.loadMessages(this.messages);
1148+
localization.locale('de');
1149+
},
1150+
afterEach: function() {
1151+
localization.locale('en');
1152+
}
1153+
}, () => {
1154+
test('borderStyle selectbox items are localized even if messages are loaded at runtime (T1234032)', function(assert) {
1155+
this.createWidget();
1156+
1157+
const $tableElement = this.$element.find('table').eq(0);
1158+
1159+
showCellPropertiesForm(this.instance, $tableElement);
1160+
1161+
this.clock.tick(10);
1162+
1163+
const formBorderItem = this.getFormInstance().option('items')[0];
1164+
const borderStyleEditor = formBorderItem.items[0];
1165+
const firstListItem = borderStyleEditor.editorOptions.items[0];
1166+
1167+
assert.strictEqual(firstListItem.value, 'Test', 'borderStyleEditor is correctly localized');
1168+
});
1169+
});
11391170
});

0 commit comments

Comments
 (0)