May 07, 2021 Vue CLI
Follow these simple steps to submit a translation for the CLI UI in another language!
You can refer to the English regional documents here.
As an example, refer to a package in French.
You can also place regional files compatible with vue-i18n in the locales folder of the root of the plug-in. D oing so automatically loads when the project opens, and then you can use $t to translate strings in your components and vue-i18n auxiliary functions. Strings used by the same UI API (like describeTask) will go into vue-i18n so you can localize them.
Example Locales folder:
vue-cli-plugin/locales/en.json
vue-cli-plugin/locales/fr.json
Examples of API usage:
api.describeConfig({
// vue-i18n 路径
description: 'com.my-name.my-plugin.config.foo'
})
Dangerous
Make sure you set the correct namespace for id because it needs to be unique across all plug-ins. We recommend using reverse domain name notation.
Examples used in components:
<VueButton>{{ $t('com.my-name.my-plugin.actions.bar') }}</VueButton>
If you prefer, you can use ClientAddonApi to load regional files in one client addon:
// 加载本地文件 (使用 vue-i18n)
const locales = require.context('./locales', true, /[a-z0-9]+\.json$/i)
locales.keys().forEach(key => {
const locale = key.match(/([a-z0-9]+)\./i)[1]
ClientAddonApi.addLocalization(locale, locales(key))
})