首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nuxt和i18n: Google显示混合语言结果

Nuxt和i18n: Google显示混合语言结果
EN

Stack Overflow用户
提问于 2020-08-11 13:56:51
回答 2查看 1.5K关注 0票数 3

我用Nuxt做了个网站。

该网站有两种语言:意大利语(默认)和其他人的英语。我安装了nuxt-i18n并配置了它,一切看起来都很好(特别是在查看devtools、html lang、rel=alternate等代码时)。

但问题是:当我用谷歌(意大利语)搜索网站时,SERP中的站点片段是英文的。

这是我的密码:

代码语言:javascript
复制
    ['nuxt-i18n', {
      seo: false,
      baseUrl: 'https://www.leconturbanti.it',
      locales: [
        {
          name: 'Italiano',
          code: 'it',
          iso: 'it-IT',
          file: 'it-IT.js'
        },
        {
          name: 'English',
          code: 'en',
          iso: 'en-US',
          file: 'en-US.js'
        },
      ],
      pages: {
        'contatti/index': {
          it: '/contatti',
          en: '/contact-us'
        },
        'illustrazioni-collezione/index': {
          it: '/illustrazioni-collezione',
          en: '/illustrations-capsule'
        }
      },
      langDir: 'lang/',
      parsePages: false,
      defaultLocale: 'it',
      lazy: true
    }]

我将seo: false设置为更好的性能,如文档中所解释的那样,并将默认布局中的数据合并:

代码语言:javascript
复制
    head(){
      return{
        script:[
          {type: `text/javascript`, innerHTML: this.$t('policy.cookieId')},
          {src: `//cdn.iubenda.com/cs/iubenda_cs.js`, charset: `UTF-8`, type: `text/javascript`}
        ],
        __dangerouslyDisableSanitizers: ['script'],
        ...this.$nuxtI18nSeo()
      }
    },

我还为$thead()中的每个页面设置了元标记。例如,在家里:

代码语言:javascript
复制
    head(){
      return{
        title: this.$t('seo.home.title'),
        meta: [
          { hid: 'description', name: 'description', content: this.$t('seo.home.description')},
          { hid: 'og:title', property: 'og:title', content: this.$t('seo.home.title') },
          { hid: 'og:url', property: 'og:url', content: this.$t('seo.home.url') },
          { hid: 'twitter:title', property: 'twitter:title', content: this.$t('seo.home.title') },
          { hid: 'og:description', property: 'og:description', content: this.$t('seo.home.description') },
          { hid: 'twitter:description', property: 'twitter:description', content: this.$t('seo.home.description') },
        ]     
      }
    },

我不明白我做错了什么。我已经在搜索控制台中添加了这个站点。如果您需要访问它进行检查,网址是:www.leconturbanti.it

如果你需要更多的我的代码来回答,只需问。谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-08-28 23:08:49

发现这个问题来自nuxt-i18n本身。问题是Google Crawler会退回到页面的英文版本,如果默认使用另一个区域设置,这就不好了。更多在这里。

目前,在问题解决之前,我使用的解决方法是禁用自动检测语言,以避免使用detectBrowserLanguage: false重定向。

票数 3
EN

Stack Overflow用户

发布于 2022-10-29 15:40:31

我的裸体头像:

代码语言:javascript
复制
head(){
    return {
      ...this.$nuxtI18nHead({ addDirAttribute: true, addSeoAttributes: true }),
      title: this.page.title,
      meta: [
        {
          property: 'og:description',
          name: 'description',
          content: this.page.description
        },
        {
          property: 'og:title',
          name: 'title',
          content: this.page.title
        }
      ],
    }
  },

我的nuxt.config.js

代码语言:javascript
复制
i18n: {
    locales ,
    strategy: 'prefix',//no_prefix , prefix , prefix_and_default ,prefix_except_default
    vueI18nLoader: true,
    defaultLocale: process.env.LOCALE_DEFAULT||'en',
    langDir: '~/locales/',
    vueI18n: {
      silentTranslationWarn: true
    },
    detectBrowserLanguage: false
  },
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63359724

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档