我正在nuxt中创建一个国际博客。我似乎无法访问导航组件和某些页面上的i18n对象。您能否阐明如何访问它以及为什么我不能访问它?我假设它与生命周期有关,但不确定...
在nuxt-config.js中:
...
modules: [
'nuxt-i18n',
'@nuxt/content'
],
i18n:{
strategy: 'prefix_and_default',
defaultLocale: 'en',
langDir: 'lang/',
lazy: true,
locales: [
{
name: '日本語',
code: 'ja',
iso: 'ja-JP',
file: 'ja-JP.js'
},
{
name: 'English',
code: 'en',
iso: 'en-US',
file: 'en-US.js'
},
],
detectBrowserLanguage: {
// If enabled, a cookie is set once a user has been redirected to his
// preferred language to prevent subsequent redirections
// Set to false to redirect every time
useCookie: true,
// Set to override the default domain of the cookie. Defaults to host of the site.
cookieDomain: null,
// Cookie name
cookieKey: 'i18n_redirected',
// Set to always redirect to value stored in the cookie, not just once
alwaysRedirect: false,
// If no locale for the browsers locale is a match, use this one as a fallback
}
},
...
我试图根据语言引入不同的降价文件,所以我打电话:
export default {
async asyncData({ $content, params}) {
const data = await $content(`${i18n.locale}/data`, params.slug).fetch()
return { data }
},
在内容上我有en/data/...
和ja/data/...
,如果我将其硬编码为en/data/
或ja/data
,它可以工作,但是我得到的是i18n是未定义的错误,我尝试了几次模式,但没有成功。