【问题标题】:Vuepress InternationalizationVuepress 国际化
【发布时间】:2019-02-09 18:10:19
【问题描述】:

我目前正在使用 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'},
            ]   
            }
        }

    }
}

我还有一张我的文件夹结构的图片:

我希望有人知道这个问题的答案,以便我继续。

亲切的问候

【问题讨论】:

    标签: javascript vue.js vuepress


    【解决方案1】:

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

    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'},
                    ]   
                }
            }
        }
    }
    

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

    【讨论】:

    • 上面的代码不起作用。我什至试图把我的英文文件夹放在公用文件夹中。但没有结果...
    【解决方案2】:

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

    您在配置中犯了一个简单的错误 - 您将常规 locale 选项放在了 themeConfig 中。

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

    您的配置应如下所示:

    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 */]
          },
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-15
      • 2015-08-31
      • 2011-12-27
      • 2021-12-10
      • 2019-10-08
      • 2011-10-27
      • 2012-02-22
      相关资源
      最近更新 更多