Vuepress 国际化

Vuepress Internationalization

我目前正在使用 Vuepress。但是我想要在我的 Vuepress 站点中使用多种语言。经过 3 天的挣扎,我决定把我的问题放在这里。 (是的,我查看了 Vuepress 文档:https://vuepress.vuejs.org/guide/i18n.html#default-theme-i18n-config

问题:在我的配置中,我将荷兰语作为主要语言。当我想将英语设置为语言环境时。我的导航不会更新。这是我的配置:

module.exports = {
    title: 'Portfolio Bjorn',
    description: ' ',
    themeConfig: {
        nav: [
            { text: 'Over mij', link: '/overmij.html'},
            { text: 'Portolfio', link: '/portfolio/'},
            { text: 'Contact', link: '/contact.html'},
            {
                text: 'Languages',
                items: [
                  { text: 'Dutch', link: '/' },
                  { text: 'English', link: '/english/' }
                ]
            } 
        ],
        sidebar: {
            '/portfolio/': [
                '',
                'school',
                'zelfgemaakt'

            ]
        },
        locales: {

            '/english': {
            lang: 'en-Us',
            nav: [
            { text: 'About', link: '/about.html'},
            { text: 'Portfolio', link: '/portfolio_en/'},
            { text: 'Contact', link: '/contact_en.html'},
            ]   
            }
        }

    }
}

我也有我的文件夹结构的图片:

我希望有人知道这个问题的答案,这样我才能继续。

亲切的问候

我认为您需要设置基本语言环境,并在那里设置默认值,而不是上面的标准方式,例如:

module.exports = {
    title: 'Portfolio Bjorn',
    description: ' ',
    themeConfig: {
        locales: {
            '/': {
                label: 'Dutch',
                nav: [
                    { text: 'Over mij', link: '/overmij.html'},
                    { text: 'Portolfio', link: '/portfolio/'},
                    { text: 'Contact', link: '/contact.html'},
                ]
            },
            '/english': {
                label: 'English',
                nav: [
                    { text: 'About', link: '/about.html'},
                    { text: 'Portfolio', link: '/portfolio_en/'},
                    { text: 'Contact', link: '/contact_en.html'},
                ]   
            }
        }
    }
}

你也不需要在导航中定义语言下拉菜单,我相信当你设置多语言时它会自动触发

我假设您使用的是默认主题。

您在配置中犯了一个简单的错误 – 您在 themeConfig.

中放置了常规 locale 选项

相反,您通常需要为站点定义区域设置,然后您还可以定义特定于主题配置的本地化数据。

您的配置应如下所示:

module.exports = {

  locales: {
    /* This is where you place your general locale config */
    '/': {
      lang: 'nl-NL',
    },
    '/en/': {
      lang: 'en-US',
      title: 'english title of the website'
    }
  },


  themeConfig: {
    locales: {
      /* This is where you place your theme specific, localized data */
      '/': {
        nav: [/* dutch nav */]
      },
      '/en/': {
        nav: [/* english nav */]
      },
    }
  }
}