-
-
Notifications
You must be signed in to change notification settings - Fork 41
Default Locale Messages #191
Comments
* Update `defaultLocaleMessages`
Thank you for your reporting! @pixari |
I have a project that ran Turns out that the bug was introduced by the code generated by this plugin. Let's compare the key piece from generated code (complete code is at the end): // before
messages[locale] = locales(key).default
// after
messages[locale] = locales(key) The problem is that Before: {
"en": {
"default": {}
}
} After: {
"en": {}
} Complete code comparison generated by Before: import { createI18n } from 'vue-i18n'
/**
* Load locale messages
*
* The loaded `JSON` locale messages is pre-compiled by `@intlify/vue-i18n-loader`, which is integrated into `vue-cli-plugin-i18n`.
* See: https://github.com/intlify/vue-i18n-loader#rocket-i18n-resource-pre-compilation
*/
function loadLocaleMessages() {
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i)
const messages = {}
locales.keys().forEach(key => {
const matched = key.match(/([A-Za-z0-9-_]+)\./i)
if (matched && matched.length > 1) {
const locale = matched[1]
messages[locale] = locales(key).default
}
})
return messages
}
export default createI18n({
locale: process.env.VUE_APP_I18N_LOCALE || 'en',
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
messages: loadLocaleMessages()
}) After: import { createI18n } from 'vue-i18n'
/**
* Load locale messages
*
* The loaded `JSON` locale messages is pre-compiled by `@intlify/vue-i18n-loader`, which is integrated into `vue-cli-plugin-i18n`.
* See: https://github.com/intlify/vue-i18n-loader#rocket-i18n-resource-pre-compilation
*/
function loadLocaleMessages() {
const locales = require.context('./locales', true, /[A-Za-z0-9-_,\s]+\.json$/i)
const messages = {}
locales.keys().forEach(key => {
const matched = key.match(/([A-Za-z0-9-_]+)\./i)
if (matched && matched.length > 1) {
const locale = matched[1]
messages[locale] = locales(key)
}
})
return messages
}
export default createI18n({
legacy: false,
locale: process.env.VUE_APP_I18N_LOCALE || 'en',
fallbackLocale: process.env.VUE_APP_I18N_FALLBACK_LOCALE || 'en',
messages: loadLocaleMessages()
}) |
Module versions:
vue-cli-plugin-i18n
: 2.xTo Reproduce
Steps to reproduce the behavior:
Expected behavior
The installation creates a default file in the locale directory for the default locale. A component is also created, with an
i18n
block, with a translated string and a call to$t
within the template to show this translated string.All translated string keys should match however, the key created in the default locale file is different to that in the i18n block and the template section.
Screenshots
Additional context
As the key/value is in the SFC i18n block, then the component shows the string correctly however, there are still warnings produced due to the mismatch in data.
The text was updated successfully, but these errors were encountered: