The defineI18nLocale()
composable is used to define a function to dynamically load locale messages used for lazy-loading translations.
The loader function needs to return a Promise
that resolves a messages object.
declare function defineI18nLocale<Messages = LocaleMessages<DefineLocaleMessage>, Locales = Locale>(
loader: (locale: Locales) => Messages | Promise<Messages>
): (locale: Locales) => Messages | Promise<Messages>
loader
A function that is the dynamic locale messages loading, that has the following parameters:
locale
Locale
setLocale()
.<NuxtLink>
. for example, the route path resolved by useSwitchLocalePath()
or $switchLocalePath()
.An example of a loader function using a fetch request to load locale messages:
export default defineI18nLocale(locale => {
return $fetch(`https://your-company-product/api/${locale}`)
})
defineI18nConfig
The defineI18nConfig() composables is used to define a function which returns the vue-i18n configuration which is passed to the createI18n() options on the Nuxt I18n module.
defineI18nLocaleDetector
The defineI18nLocaleDetector() is composable used to define a function which detects the locale on the server-side, it's called per request on the server.