Skip to content

Commit e035870

Browse files
feat(localization): Integration of new i18nManager resource strings. (#1835)
--------- Co-authored-by: Radoslav Karaivanov <[email protected]>
1 parent efd5920 commit e035870

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1082
-148
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ i18nRepo
3535
.env
3636
.envrc
3737
.direnv
38+
39+
.vs

.storybook/preview.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ import { type CSSResult, html } from 'lit';
44
import { configureTheme } from '../src/theming/config';
55
import type { Decorator, Preview } from '@storybook/web-components-vite';
66
import { withActions } from 'storybook/actions/decorator';
7+
import { registerI18n } from 'igniteui-i18n-core';
8+
import {
9+
ResourceStringsBG,
10+
ResourceStringsDE,
11+
ResourceStringsES,
12+
ResourceStringsFR,
13+
ResourceStringsJA,
14+
} from 'igniteui-i18n-resources';
15+
16+
const LocalizationResources = new Map(
17+
Object.entries({
18+
de: ResourceStringsDE,
19+
fr: ResourceStringsFR,
20+
es: ResourceStringsES,
21+
ja: ResourceStringsJA,
22+
bg: ResourceStringsBG,
23+
})
24+
);
725

826
type ThemeImport = { styles: CSSResult };
927

@@ -62,6 +80,12 @@ const themeProvider: Decorator = (story, context) => {
6280
`;
6381
};
6482

83+
const localeProvider: Decorator = (story, context) => {
84+
const { localization } = context.globals;
85+
document.documentElement.lang = localization ?? 'en';
86+
return story();
87+
};
88+
6589
export default {
6690
globalTypes: {
6791
theme: {
@@ -102,6 +126,21 @@ export default {
102126
],
103127
},
104128
},
129+
localization: {
130+
name: 'Localization',
131+
description: 'Component localization',
132+
toolbar: {
133+
icon: 'globe',
134+
items: [
135+
{ value: 'en', title: 'English' },
136+
{ value: 'de', title: 'German' },
137+
{ value: 'fr', title: 'French' },
138+
{ value: 'es', title: 'Spanish' },
139+
{ value: 'ja', title: 'Japanese' },
140+
{ value: 'bg', title: 'Bulgarian' },
141+
],
142+
},
143+
},
105144
size: {
106145
name: 'Size',
107146
description: 'Component size',
@@ -120,16 +159,21 @@ export default {
120159
theme: 'bootstrap',
121160
variant: 'light',
122161
direction: 'ltr',
162+
localization: 'en',
123163
size: 'default',
124164
},
125165
parameters: {
126166
backgrounds: {
127167
disable: true,
128168
},
129169
},
130-
decorators: [themeProvider, withActions],
170+
decorators: [themeProvider, withActions, localeProvider],
131171
loaders: [
132172
async (context) => {
173+
for (const [locale, resources] of LocalizationResources.entries()) {
174+
registerI18n(resources, locale);
175+
}
176+
133177
const { theme, variant } = context.globals;
134178
return { theme: getTheme({ theme, variant }) };
135179
},

package-lock.json

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"@floating-ui/dom": "^1.7.4",
5757
"@lit-labs/virtualizer": "^2.1.1",
5858
"@lit/context": "^1.1.6",
59-
"lit": "^3.3.1"
59+
"lit": "^3.3.1",
60+
"igniteui-i18n-core": "0.6.0-alpha.4"
6061
},
6162
"devDependencies": {
6263
"@biomejs/biome": "~2.2.6",
@@ -80,6 +81,7 @@
8081
"globby": "^15.0.0",
8182
"husky": "^9.1.7",
8283
"ig-typedoc-theme": "^6.2.3",
84+
"igniteui-i18n-resources": "0.6.0-alpha.4",
8385
"igniteui-theming": "^20.0.0",
8486
"keep-a-changelog": "^2.7.1",
8587
"lint-staged": "^16.2.4",

src/components/calendar/base.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import { property, state } from 'lit/decorators.js';
44
import { blazorDeepImport } from '../common/decorators/blazorDeepImport.js';
55
import { blazorIndirectRender } from '../common/decorators/blazorIndirectRender.js';
66
import { watch } from '../common/decorators/watch.js';
7+
import {
8+
IgcCalendarResourceStringEN,
9+
type IgcCalendarResourceStrings,
10+
} from '../common/i18n/EN/calendar.resources.js';
11+
import { addI18nController } from '../common/i18n/i18n-controller.js';
712
import { first } from '../common/util.js';
813
import { convertToDate, convertToDates, getWeekDayNumber } from './helpers.js';
914
import { CalendarDay } from './model.js';
@@ -16,6 +21,10 @@ import type {
1621
@blazorIndirectRender
1722
@blazorDeepImport
1823
export class IgcCalendarBaseComponent extends LitElement {
24+
protected readonly _i18nController =
25+
addI18nController<IgcCalendarResourceStrings>(this, {
26+
defaultEN: IgcCalendarResourceStringEN,
27+
});
1928
private _initialActiveDateSet = false;
2029

2130
protected get _hasValues() {
@@ -130,7 +139,25 @@ export class IgcCalendarBaseComponent extends LitElement {
130139
* @attr locale
131140
*/
132141
@property()
133-
public locale = 'en';
142+
public set locale(value: string) {
143+
this._i18nController.locale = value;
144+
}
145+
146+
public get locale() {
147+
return this._i18nController.locale;
148+
}
149+
150+
/**
151+
* The resource strings for localization.
152+
*/
153+
@property({ attribute: false })
154+
public set resourceStrings(value: IgcCalendarResourceStrings) {
155+
this._i18nController.resourceStrings = value;
156+
}
157+
158+
public get resourceStrings(): IgcCalendarResourceStrings {
159+
return this._i18nController.resourceStrings;
160+
}
134161

135162
/** Gets/Sets the special dates for the component. */
136163
@property({ attribute: false })

src/components/calendar/calendar-rendering.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('Calendar Rendering', () => {
6262
`
6363
<div part="header">
6464
<h5 part="header-title">
65-
<slot name="title">Select date</slot>
65+
<slot name="title">Select Date</slot>
6666
</h5>
6767
<h2 part="header-date">
6868
<slot>

src/components/calendar/calendar.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import {
1717
} from '../common/controllers/key-bindings.js';
1818
import { watch } from '../common/decorators/watch.js';
1919
import { registerComponent } from '../common/definitions/register.js';
20-
import { IgcCalendarResourceStringEN } from '../common/i18n/calendar.resources.js';
2120
import { createDateTimeFormatters } from '../common/localization/intl-formatters.js';
2221
import type { Constructor } from '../common/mixins/constructor.js';
2322
import { EventEmitterMixin } from '../common/mixins/event-emitter.js';
@@ -220,12 +219,6 @@ export default class IgcCalendarComponent extends EventEmitterMixin<
220219
public formatOptions: Pick<Intl.DateTimeFormatOptions, 'month' | 'weekday'> =
221220
{ month: 'long', weekday: 'narrow' };
222221

223-
/**
224-
* The resource strings for localization.
225-
*/
226-
@property({ attribute: false })
227-
public resourceStrings = IgcCalendarResourceStringEN;
228-
229222
private _intl = createDateTimeFormatters(this.locale, {
230223
month: {
231224
month: this.formatOptions.month,

src/components/calendar/days-view/days-view.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { blazorIndirectRender } from '../../common/decorators/blazorIndirectRend
77
import { blazorSuppressComponent } from '../../common/decorators/blazorSuppressComponent.js';
88
import { watch } from '../../common/decorators/watch.js';
99
import { registerComponent } from '../../common/definitions/register.js';
10-
import { IgcCalendarResourceStringEN } from '../../common/i18n/calendar.resources.js';
1110
import { createDateTimeFormatters } from '../../common/localization/intl-formatters.js';
1211
import type { Constructor } from '../../common/mixins/constructor.js';
1312
import { EventEmitterMixin } from '../../common/mixins/event-emitter.js';
@@ -101,10 +100,6 @@ export default class IgcDaysViewComponent extends EventEmitterMixin<
101100
return this._rangePreviewDate?.native;
102101
}
103102

104-
/** The resource strings. */
105-
@property({ attribute: false })
106-
public resourceStrings = IgcCalendarResourceStringEN;
107-
108103
/**
109104
* The format of the days. Defaults to narrow.
110105
* @attr week-day-format

src/components/carousel/carousel.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,12 @@ describe('Carousel', () => {
133133
)?.id;
134134
expect(carousel).shadowDom.to.equal(
135135
`<section>
136-
<igc-button aria-label="Previous slide" aria-controls="${carouselId}">
136+
<igc-button aria-label="previous slide" aria-controls="${carouselId}">
137137
<slot name="previous-button">
138138
<igc-icon aria-hidden="true" collection="default" name="carousel_prev"></igc-icon>
139139
</slot>
140140
</igc-button>
141-
<igc-button aria-label="Next slide" aria-controls="${carouselId}">
141+
<igc-button aria-label="next slide" aria-controls="${carouselId}">
142142
<slot name="next-button">
143143
<igc-icon aria-hidden="true" collection="default" name="carousel_next"></igc-icon>
144144
</slot>

0 commit comments

Comments
 (0)