mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* feat: support numeric input in dashboard filters * fix: show only the numeric filter error outline * fix: recover stale filters in shared dashboards * fix: initialize the English translation fallback
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
import moment from '@baserow/modules/core/moment'
|
|
|
|
export default defineNuxtPlugin({
|
|
name: 'i18n',
|
|
async setup(nuxtApp) {
|
|
const { $i18n } = nuxtApp
|
|
// Resolved lazily, because the first call creates the indicator with its
|
|
// options, and those must come from the `NuxtLoadingIndicator` in `app.vue`.
|
|
const getLoadingIndicator = () =>
|
|
nuxtApp.runWithContext(() => useLoadingIndicator())
|
|
|
|
// Public pages can set the browser locale directly after plugin setup.
|
|
$i18n.fallbackLocale.value = 'en'
|
|
moment.locale($i18n.locale.value)
|
|
|
|
const loadFallbackIfNeeded = async (locale) => {
|
|
if (locale !== 'en') {
|
|
try {
|
|
await $i18n.loadLocaleMessages('en')
|
|
} catch (error) {
|
|
console.warn('Failed to load fallback locale messages:', error)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Use watch to react to client side locale switch
|
|
watch($i18n.locale, (newLocale) => {
|
|
moment.locale(newLocale)
|
|
})
|
|
|
|
// Switching the language downloads the messages of the new locale, which can
|
|
// take a while on a slow connection, so the progress bar is shown until
|
|
// everything of the new locale has been loaded.
|
|
nuxtApp.hook('i18n:beforeLocaleSwitch', () => {
|
|
// `initialSetup` can't be used to skip the first page load, because it's
|
|
// never reset with the `no_prefix` strategy.
|
|
if (import.meta.client && !nuxtApp.isHydrating) {
|
|
getLoadingIndicator().start()
|
|
}
|
|
})
|
|
nuxtApp.hook('i18n:localeSwitched', async ({ newLocale }) => {
|
|
try {
|
|
await loadFallbackIfNeeded(newLocale)
|
|
} finally {
|
|
if (import.meta.client) {
|
|
getLoadingIndicator().finish()
|
|
}
|
|
}
|
|
})
|
|
|
|
await loadFallbackIfNeeded($i18n.locale.value)
|
|
},
|
|
})
|