Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 使用i18n标记进行翻译_Vue.js_Vue I18n - Fatal编程技术网

Vue.js 使用i18n标记进行翻译

Vue.js 使用i18n标记进行翻译,vue.js,vue-i18n,Vue.js,Vue I18n,我对我的新Vuejs项目有一个问题,我使用vuei18n的方式与我公司的其他项目相同,但在新项目中标记不起作用。 当我在i18n/index.js中禁用silentTranslationWarn时,我收到以下消息: [vue-i18n]键“页面”的值不是字符串! [vue-i18n]无法转换键路径“页面”的值。使用keypath的值作为默认值 当我像这样将我的翻译放在i18n/fr.js中时,我的翻译工作: const messages = { pages: 'Pages', }; 但当我

我对我的新Vuejs项目有一个问题,我使用vuei18n的方式与我公司的其他项目相同,但在新项目中标记不起作用。 当我在i18n/index.js中禁用silentTranslationWarn时,我收到以下消息:

[vue-i18n]键“页面”的值不是字符串! [vue-i18n]无法转换键路径“页面”的值。使用keypath的值作为默认值

当我像这样将我的翻译放在i18n/fr.js中时,我的翻译工作:

const messages = {
  pages: 'Pages',
};
但当我想在组件中使用标记时,就像在旧项目中一样,我之前已经描述了vue-i18n警告。 我在旧项目中搜索了所有出现的“i18n”、“本地”、“消息”等。。。但在新项目中,我的package.json中出现了完全相同的情况,我有相同版本的vue-i18n

我错过什么了吗?

@kalidou.diagne:

在我的i18n/index.js中:

import Vue from 'vue';
import VueI18n from 'vue-i18n';

import en from './en';
import fr from './fr';

Vue.use(VueI18n);
const messages = { en, fr };

export default new VueI18n({
  locale: 'fr',
  silentTranslationWarn: true,
  messages,
});
在my main.js中:

import i18n from './i18n';

...

const Mdm = Vue.component('app', App);

/* eslint-disable no-new */
new Mdm({
  el: '#app',
  i18n,
  router,
  store,
  components: { App },
  template: '<App/>',
});
从“/i18n”导入i18n;
...
const Mdm=Vue.component('app',app);
/*eslint禁用无新*/
新Mdm({
el:“#应用程序”,
i18n,
路由器,
商店,
组件:{App},
模板:“”,
});
@kalidou.diagne:

在我的i18n/index.js中:

import Vue from 'vue';
import VueI18n from 'vue-i18n';

import en from './en';
import fr from './fr';

Vue.use(VueI18n);
const messages = { en, fr };

export default new VueI18n({
  locale: 'fr',
  silentTranslationWarn: true,
  messages,
});
在my main.js中:

import i18n from './i18n';

...

const Mdm = Vue.component('app', App);

/* eslint-disable no-new */
new Mdm({
  el: '#app',
  i18n,
  router,
  store,
  components: { App },
  template: '<App/>',
});
从“/i18n”导入i18n;
...
const Mdm=Vue.component('app',app);
/*eslint禁用无新*/
新Mdm({
el:“#应用程序”,
i18n,
路由器,
商店,
组件:{App},
模板:“”,
});

您是否正确创建了vue i18n实例?你能提供一个例子吗?你如何称呼i18n?尝试将
$t('messages.pages')
this
一起在代码行或代码中使用。是否正确创建了vue i18n实例?你能提供一个例子吗?你如何称呼i18n?尝试将
$t('messages.pages')
this一起使用。