Skip to content

Commit 7a2a8fc

Browse files
authored
handle client side locale switch withen fallback (baserow#4799)
1 parent 4780c3a commit 7a2a8fc

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

  • web-frontend/modules/core/plugins

web-frontend/modules/core/plugins/i18n.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@ export default defineNuxtPlugin({
77

88
moment.locale($i18n.locale.value)
99

10-
$i18n.onLanguageSwitched = (oldLocale, newLocale) => {
11-
moment.locale(newLocale)
12-
}
13-
14-
if ($i18n.locale.value !== 'en') {
15-
try {
16-
$i18n.fallbackLocale.value = 'en'
17-
await $i18n.loadLocaleMessages('en')
18-
} catch (error) {
19-
console.warn('Failed to load fallback locale messages:', error)
10+
const loadFallbackIfNeeded = async (locale) => {
11+
if (locale !== 'en') {
12+
try {
13+
$i18n.fallbackLocale.value = 'en'
14+
await $i18n.loadLocaleMessages('en')
15+
} catch (error) {
16+
console.warn('Failed to load fallback locale messages:', error)
17+
}
2018
}
2119
}
20+
21+
// Use watch to react to client side locale switch
22+
watch($i18n.locale, async (newLocale, oldLocale) => {
23+
moment.locale(newLocale)
24+
await loadFallbackIfNeeded(newLocale)
25+
})
26+
27+
await loadFallbackIfNeeded($i18n.locale.value)
2228
},
2329
})

0 commit comments

Comments
 (0)