Skip to content

Commit b413402

Browse files
committed
fix: move event listener
1 parent 98f10f2 commit b413402

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

.storybook/preview.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ globalThis['__NUXT_COLOR_MODE__'] ??= {
1919
// @ts-expect-error - dynamic global name
2020
globalThis.defineOgImageComponent = fn()
2121

22+
// Subscribe to locale changes from storybook-i18n addon (once, outside decorator)
23+
let currentI18nInstance: any = null
24+
addons.getChannel().on('LOCALE_CHANGED', (newLocale: string) => {
25+
if (currentI18nInstance) {
26+
currentI18nInstance.setLocale(newLocale)
27+
}
28+
})
29+
2230
const preview: Preview = {
2331
parameters: {
2432
controls: {
@@ -81,21 +89,11 @@ const preview: Preview = {
8189
document.documentElement.style.removeProperty('--accent-color')
8290
}
8391

84-
// Store reference to i18n instance for locale changes
85-
let i18nInstance: any = null
86-
87-
// Subscribe to locale changes from storybook-i18n addon
88-
addons.getChannel().on('LOCALE_CHANGED', (newLocale: string) => {
89-
if (i18nInstance) {
90-
i18nInstance.setLocale(newLocale)
91-
}
92-
})
93-
9492
return {
9593
template: '<story />',
9694
created() {
9795
// Store i18n instance for LOCALE_CHANGED events
98-
i18nInstance = this.$i18n
96+
currentI18nInstance = this.$i18n
9997

10098
// Set initial locale when component is created
10199
if (locale && this.$i18n) {

0 commit comments

Comments
 (0)