- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经成功地很好地集成了 vue-i18n我的开发环境中的库并且运行良好。
但是,当我在 Heroku 上部署项目时,每条消息都使用 vue-i18n Pluralization或Linked Locale Messages不被解释并显示整个区域设置消息字符串:
我已经就该存储库展开了讨论,但到目前为止还没有回复...
我正在 Nuxt3 中使用 vue-i18n (9.2.2)插件,因此使用 VueJS 3 ,用 Vite 构建使用 vue-i18n 插件 vite-plugin-vue-i18n .
Nuxt3 配置 (nuxt.config.ts),显示用于解析语言环境 JSON 文件的 Vite 插件配置:
import { defineNuxtConfig } from 'nuxt'
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'url'
import VueI18nVitePlugin from '@intlify/unplugin-vue-i18n/vite'
export default defineNuxtConfig({
...
vite: {
plugins: [
VueI18nVitePlugin({
include: [
resolve(dirname(fileURLToPath(import.meta.url)), './locales/*.json')
]
})
]
},
...
});
vue-i18n 的 Nuxt 插件 (plugins/vue-i18n.ts) :
import { createI18n } from 'vue-i18n'
import fr from '~/locales/fr.json'
import en from '~/locales/en.json'
// DOC I18N : https://www.i18next.com/translation-function/essentials
export default defineNuxtPlugin(({ vueApp }) => {
const i18n = createI18n({
legacy: false,
allowComposition: true,
globalInjection: true,
locale: 'fr',
fallbackLocale: 'en',
messages: {
'en': en,
'fr': fr,
}
});
vueApp.use(i18n);
})
这是 2 个语言环境文件:
locales/fr.json:
{
"test": "Zero test | Un test | {n} tests",
"testnested": {
"nestedvalue": "Zero sous-test | Un sous-test | {n} sous-tests"
},
...
locales/en.json:
"test": "Zero test | One test | {n} tests",
"testnested": {
"nestedvalue": "Zero sub-test | Un sub-test | {n} sub-tests"
},
...
}
如何在 Vue 模板中使用区域设置消息的示例:
<p>
-- TEST ROOT --<br />
{{ $t('test', 0) }}<br />
{{ $t('test', 1) }}<br />
{{ $t('test', 2) }}<br />
<br />
-- TEST NESTED --<br />
{{ $t('testnested.nestedvalue', 0) }}<br />
{{ $t('testnested.nestedvalue', 1) }}<br />
{{ $t('testnested.nestedvalue', 2) }}<br />
</p>
语言环境消息中的复数和链接消息语法应由 vue-i18n 解释,并且不显示完整的语言环境消息字符串。
[预期]本地环境输出:
[BUG 结果] 为生产打包相同的代码,部署在 Heroku 上:
链接消息失败的另一个示例(生产中):
以下是有关我的系统的一些信息:
System:
OS: Windows 10 10.0.22000
CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
Memory: 16.35 GB / 31.59 GB
Binaries:
Node: 16.13.2 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.17 - C:\Program Files\nodejs\yarn.CMD
npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Spartan (44.22000.120.0),
Chromium (105.0.1343.27)
Internet Explorer: 11.0.22000.120
npmPackages:
@intlify/unplugin-vue-i18n: ^0.5.0 => 0.5.0
vitest: ^0.20.3 => 0.20.3
vue-i18n: ^9.2.2 => 9.2.2
vue-toastification: next => 2.0.0-rc.5
我已阅读其他线程和 StackOverflow here但接受的答案似乎不是最新的,并且相信 webpack 或 vite 打包项目的方式可能存在问题。
我在这里做错了什么?
如果没有任何问题,您会建议我在 vue-i18n 存储库上打开错误报告吗?或者在 @intlify/vite-plugin-vue-i18n 存储库上?
最佳答案
我也遇到了同样的问题。
认为这是将消息转换为 JS 函数的 vite-plugin-vue-i18n 预编译的问题。我在 vite.config.js 中设置了 runtimeOnly:false,然后它在 Production 中的工作方式与 HMR 中的工作方式相同。
关于vue.js - Vue i18n : Pluralization and Linked Messages not interpreted in production,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73648958/
我在将过滤器从 vue 1 迁移到 vue 2 时遇到问题,我在这里完全创建了我需要的东西(突出显示与输入文本匹配的文本): Vue.component('demo-grid', { templa
我有一个在 vue 组件外部运行的函数。我想要将它返回的数据传递给vue组件中的数据。 function example(){ var item = 'item'
我正在尝试安装一个 Vue 插件,以便我可以使用选项管理一些 API 调用。我有一个 stocks.js 文件,我想从中进行 API 调用。 当我执行以下操作时,出现'Vue is defined b
如何从指令访问 Vue 实例? 我有这个 HTML 和这个脚本 var app = new Vue({ el: '#vueApp', data: { myData:
如何在 .vue 文件中使用 Vue.set() 和 Vue.use()?我正在使用 vue-cli 搭建我的项目,我需要使用 Vue.use(VeeValidate) 进行验证。我也想使用类似下面的
从 vue-property-decorator 和 vue 导入 Vue 之间有什么区别和用例?据我所知,在使用 @Component 装饰器定义自定义组件时,我始终需要从 vue-property
有没有办法使用 yarn serve(可能使用 webpack/vuetify-loader)在本地 Vuetify 应用程序的本地 npm 依赖项上发生热重载? 商业案例 我们有一些通用的 Vuet
我有一个在某些未知情况下不可靠的插槽的奇怪错误。 成分 有3个层次组件。 孙子 (headlessTable),它提供一个名为 arrayValue 的插槽. 子项 (collapsableCard)
我是 Vue 本地新手,我也遇到了一个问题,can I use the Vue component inside a Vue native component such as Vue-chart an
Vue.delete 的替代方案是什么?在 Vue 3 的新 Reactivity API 中? 最佳答案 Vue.delete和 Vue.set在 Vue 3 中不需要。通过使用代理的新 react
我是 Vue 的新手,正在尝试学习如何使用它。 我想我在尝试安装一个新的 Vue 应用程序时被绊倒了。 这是我可以开始工作的内容: const vm = new Vue({}) 从那里我可以安装
我使用boots-vue。我从文档https://bootstrap-vue.js.org/docs/components/table/#table-body-transition-support中举
我真的只是想为我的图书馆建立一个 jest+vue 的框架,并迅速得到这个错误。 我知道这个结构不是通常的笑话结构,我在这里尝试用一个辅助控件来描述一个测试。 这是我的test的内容文件夹:array
我正在尝试使用基于 examples 的 vue-router , 如 let routes = [ { path: '/', component: MainComponent }, ];
我有一个想要通过简单的 v-model 功能发布到 NPM 的组件。 因此,如果它能够在 vuejs 2/3 上互换运行那就更理想了。 我可以通过将组件设置为发出 input 和 update:mod
我正在尝试在 bootstrap-vue 表中创建一个插槽,以使用自定义组件呈现任何 bool 值。 所以我有一个简单的表格 现在,如果我想以特定方式渲染单个列,我必须使用插槽 它有
Vue Router 在主 Vue 实例之前加载,但要加载该 Router,我应该准备一些信息,然后将它们作为属性传递给此 Route。在此示例中,它是从主 Vue 实例传递到主屏幕的 current
我有一个想要通过简单的 v-model 功能发布到 NPM 的组件。 因此,如果它能够在 vuejs 2/3 上互换运行那就更理想了。 我可以通过将组件设置为发出 input 和 update:mod
我找到了一个关于如何使用 Vue 路由器的很好的例子。这是 app.js 文件: // Telling Vue to use the router Vue.use(VueRouter) // Init
我没有完整的 vue 应用程序,所以我使用 custom elements替换一些应该用 vue 处理的元素。 我只想使用 vue multiselect plugin在 html 文件中。 所以我尝
我是一名优秀的程序员,十分优秀!