Appearance
i18n
sh
yarn add -D @nuxtjs/i18n
nuxtConfig
js
export default defineNuxtConfig({
modules: ['@nuxtjs/i18n'],
i18n: {
...options,
vueI18n: '@/locales'
}
})
locales
语言列表
js
export default {
locales: ['en', 'zh'],
defaultlocale: 'en'
}
browser
浏览器语言检测
优先级要高于默认语言,可以关闭,也可以具体配置
js
export default {
detectbrowserlanguage: false
}
默认配置
js
export default {
detectbrowserlanguage: {
alwaysRedirect: false,
fallbackLocale: '',
redirectOn: 'root',
useCookie: true,
cookieCrossOrigin: false,
cookieDomain: null,
cookieKey: 'i18n_redirected',
cookieSecure: false
}
}
i18nConfig
js
export default defineI18nConfig(() => ({
legacy: false,
locale: 'en',
messages: {
en: {
welcome: 'Welcome'
},
zh: {
welcome: '欢迎'
}
}
}))