i make en-Us.js file in lang folder and put this code
export default {
"welcome" : "sdfs",
account_description: 'Account description',
}
but not loaded.
i found problem there
`/**
in line
i18n.setLocaleMessage(lang, msgs)
to
i18n.setLocaleMessage(lang, msgs.default)
its true?
Hi @roshangara !
At the moment, I'd recommend you use the "classic" export method by replacing export default { with module.exports = {. It should do the trick :)
I've tried module.exports in my lang file which integrates locale from element-ui but got an error like below
client.js:524 [nuxt] Error while initializing app TypeError: Cannot assign to read only property 'exports' of object '#<Object>'
at Object.<anonymous> (zh-CN.js:11)
at Object../lang/zh-CN.js (zh-CN.js:21)
at __webpack_require__ (bootstrap a35ddee16c4bfdf308d8:712)
at fn (bootstrap a35ddee16c4bfdf308d8:117)
at main.scss?4a09:21
at <anonymous>
here's my lang file,
var elementLocale = require('element-ui/lib/locale/lang/zh-TW').default;
module.exports = Object.assign({}, elementLocale, {
appName: 'appName',
placeholder: {
input: 'Please input {0}',
},
});
change it to es2015 syntax solves the issue but result in an expected default key in my i18n messages object.
import elementLocale from 'element-ui/lib/locale/lang/zh-TW';
export default {
...elementLocale,
appName: 'appName',
placeholder: {
input: 'Please input {0}',
},
};
How could I get around this problem?
I ended up calling app.i18n.mergeLocaleMessage(locale, elementLocale) in onLanguageSwitched(So did vee-validate's dictionary localization). Since setLocaleMessage would be called after beforeLanguageSwitch if loadLanguagesAsync is turned on.
Hi @blooddrunk . I think it's a bug in the documentation of this package. Lang files should be .json.
In nuxt.config.js for example:
modules: [
['nuxt-i18n', {
locales: [
{
code: 'en',
iso: 'en-US',
name: 'English',
langFile: 'en-US.json'
},
{
code: 'es',
iso: 'es-ES',
name: 'Espa帽ol',
langFile: 'es-ES.json'
}
],
loadLanguagesAsync: true,
langDir: 'lang/'
}]
],
@amazzoccone Location files can be js files as well! They need the correct export though (Example)
I had a similar problem and thought I would share my gist: https://gist.github.com/toadkicker/99551a94d0922e43a18aea7c6169a62e
Needed to read in YAML files from the Rails backend, and then make them available to the Nuxt application..
I need to use nuxt and i18n to add different language support to my app, the problem is that I can have the json files with the lang locally, I need to do an api call to the back end and retrieve the json file, set it to the localStorage and them consume the lang from there. I have been struggling with this the whole day. And this keep throwing an error when trying to change the route to a different language: app.i18n.beforeLanguageSwitch is not a function
This should be fixed in current version as it takes into account possible export.default property:
https://github.com/nuxt-community/nuxt-i18n/blob/a6172ec0b2387c24424d50189fee015e20232a95/src/templates/utils.js#L23-L25
Closing for now
Most helpful comment
@amazzoccone Location files can be js files as well! They need the correct export though (Example)