@@ -4,6 +4,24 @@ import { type CSSResult, html } from 'lit';
44import { configureTheme } from '../src/theming/config' ;
55import type { Decorator , Preview } from '@storybook/web-components-vite' ;
66import { 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
826type 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+
6589export 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 } ,
0 commit comments