Skip to content

Commit 18e6611

Browse files
authored
Scheduler: View switcher text is not translated by localization in v25.1.4 (#31082)
1 parent 63982b8 commit 18e6611

File tree

3 files changed

+88
-10
lines changed

3 files changed

+88
-10
lines changed

packages/devextreme/js/__internal/scheduler/header/m_utils.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import dateLocalization from '@js/common/core/localization/date';
22
import dateUtils from '@js/core/utils/date';
3-
import { isFunction } from '@js/core/utils/type';
3+
import { isFunction, isObject } from '@js/core/utils/type';
4+
import messageLocalization from '@js/localization/message';
45
import type { DateNavigatorTextInfo, Properties } from '@js/ui/scheduler';
56
import type { IntervalOptions, Step } from '@ts/scheduler/header/types';
6-
import type { NormalizedView, ViewType } from '@ts/scheduler/utils/options/types';
7+
import type { NormalizedView, RawViewType, ViewType } from '@ts/scheduler/utils/options/types';
78

89
import type { Direction } from './constants';
910

@@ -324,6 +325,27 @@ const STEP_MAP: Record<ViewType, Step> = {
324325
agenda: 'agenda',
325326
} as const;
326327

327-
export const getStep = (type: ViewType): Step => STEP_MAP[type];
328+
export const getViewName = (view: RawViewType): string | undefined => {
329+
if (isObject(view)) {
330+
return view.name ?? view.type;
331+
}
332+
333+
return view;
334+
};
335+
336+
export const getViewText = (view: RawViewType): string => {
337+
const viewName = getViewName(view);
338+
const viewText = messageLocalization.format(`dxScheduler-switcher${viewName}`);
328339

329-
export const getViewName = (view: NormalizedView): string | undefined => view.name ?? view.type;
340+
if (!viewText) {
341+
return viewName ?? '';
342+
}
343+
344+
return viewText;
345+
};
346+
347+
export const formatViews = (
348+
views: NormalizedView[],
349+
): NormalizedView[] => views.map((view) => ({ ...view, text: getViewText(view) }));
350+
351+
export const getStep = (type: ViewType): Step => STEP_MAP[type];

packages/devextreme/js/__internal/scheduler/header/m_view_switcher.integration.test.ts

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
/* eslint-disable i18n/no-russian-character */
2+
/* eslint-disable spellcheck/spell-checker */
13
import {
2-
afterEach,
3-
describe, expect, it,
4+
afterEach, describe, expect, it,
45
} from '@jest/globals';
56
import type { dxElementWrapper } from '@js/core/renderer';
67
import $ from '@js/core/renderer';
8+
import { loadMessages, locale } from '@js/localization';
79

810
import type { Properties as SchedulerProperties } from '../../../ui/scheduler';
911
import Scheduler from '../../../ui/scheduler';
@@ -14,6 +16,7 @@ const SELECTORS = {
1416
schedulerContainer: '#schedulerContainer',
1517
invisibleState: '.dx-state-invisible',
1618
viewSwitcher: '.dx-scheduler-view-switcher',
19+
viewSwitcherButton: '.dx-scheduler-view-switcher .dx-button',
1720
};
1821

1922
const createScheduler = (options: SchedulerProperties): Promise<{
@@ -85,4 +88,57 @@ describe('ViewSwitcher', () => {
8588
},
8689
);
8790
});
91+
92+
describe('Localization', () => {
93+
it('should display Russian view names when locale is set to Russian', async () => {
94+
loadMessages({
95+
ru: {
96+
'dxScheduler-switcherDay': 'День',
97+
'dxScheduler-switcherWeek': 'Неделя',
98+
'dxScheduler-switcherMonth': 'Месяц',
99+
},
100+
});
101+
locale('ru');
102+
103+
const { $container } = await createScheduler({
104+
useDropDownViewSwitcher: false,
105+
currentView: 'day',
106+
views: ['day', 'week', 'month'],
107+
});
108+
109+
const buttons = $container.find(SELECTORS.viewSwitcherButton);
110+
const buttonTexts: string[] = [];
111+
buttons.each((_, button) => {
112+
buttonTexts.push($(button).text());
113+
return true;
114+
});
115+
116+
expect(buttonTexts).toContain('День');
117+
expect(buttonTexts).toContain('Неделя');
118+
expect(buttonTexts).toContain('Месяц');
119+
});
120+
121+
it('should display Russian view names in dropdown switcher when locale is set to Russian', async () => {
122+
loadMessages({
123+
ru: {
124+
'dxScheduler-switcherDay': 'День',
125+
'dxScheduler-switcherWeek': 'Неделя',
126+
'dxScheduler-switcherMonth': 'Месяц',
127+
},
128+
});
129+
locale('ru');
130+
131+
const { $container } = await createScheduler({
132+
useDropDownViewSwitcher: true,
133+
currentView: 'day',
134+
views: ['day', 'week', 'month'],
135+
});
136+
137+
const viewSwitcher = $container.find(SELECTORS.viewSwitcher);
138+
const dropdown = viewSwitcher.find('.dx-dropdownbutton');
139+
const buttonText = dropdown.find('.dx-button-text');
140+
141+
expect(buttonText.text()).toBe('День');
142+
});
143+
});
88144
});

packages/devextreme/js/__internal/scheduler/header/m_view_switcher.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Item as ToolbarItem } from '@js/ui/toolbar';
44
import type { NormalizedView } from '../utils/options/types';
55
import type { SchedulerHeader } from './m_header';
66
import {
7+
formatViews,
78
getViewName,
89
} from './m_utils';
910

@@ -14,7 +15,7 @@ const ClASS = {
1415
};
1516

1617
const getViewsAndSelectedView = (header: SchedulerHeader) => {
17-
const views = header.option('views');
18+
const views = formatViews(header.option('views'));
1819
const selectedView = header.option('currentView').name;
1920
const isSelectedViewInViews = views.some((view) => view.name === selectedView);
2021

@@ -32,7 +33,6 @@ export const getTabViewSwitcher = (header: SchedulerHeader, item): ToolbarItem =
3233

3334
// @ts-expect-error
3435
const stylingMode = isFluent() ? 'outlined' : 'contained';
35-
const items = views.map((view) => ({ ...view, text: view.name }));
3636

3737
return {
3838
widget: 'dxButtonGroup',
@@ -42,7 +42,7 @@ export const getTabViewSwitcher = (header: SchedulerHeader, item): ToolbarItem =
4242
cssClass: ClASS.container,
4343
visible: isVisible,
4444
options: {
45-
items,
45+
items: views,
4646
keyExpr: 'name',
4747
selectedItemKeys: [selectedView],
4848
stylingMode,
@@ -77,7 +77,7 @@ export const getDropDownViewSwitcher = (header: SchedulerHeader, item): ToolbarI
7777
useSelectMode: true,
7878
keyExpr: 'name',
7979
selectedItemKey: selectedView,
80-
displayExpr: 'name',
80+
displayExpr: 'text',
8181
showArrowIcon: true,
8282
elementAttr: {
8383
class: ClASS.dropDownButton,

0 commit comments

Comments
 (0)