Vue 3 i18n 问题:此版本不支持消息格式编译

Vue 3 i18n issue: The message format compilation is not supported in this build

vue & vue-i18n 版本

例如:

描述

我可能做错了什么,但是我真的很感激一些指导。我遵循了 vue-i18n@next 的文档。翻译不起作用,我在控制台中收到消息:

[intlify] 此版本不支持消息格式编译。因为不包括消息编译器。您需要预编译所有消息格式。所以翻译函数 return 'hello'.

有什么问题,很简单?

将您的 vue-i18n 导入更改为:

import { createI18n } from 'vue-i18n/dist/vue-i18n.esm-bundler.js';

与 Vue 本身一样,i18n 包带有各种版本。与 Vue 一样,它们有带和不带运行时编译器的版本。来自 the docs:

vue-i18n.esm-bundler.js: includes the runtime compiler. Use this if you are using a bundler but still want locale messages compilation (e.g. templates via inline JavaScript strings)

这个警告显然是在告诉你你需要这个编译器。文档对此不太清楚,但这是您需要将导入指向运行时编译器版本的方式。