Hello everybody !
I am trying to use Aurelia-i18n but I run into some strange issue. After having quite some difficulties to make it work by looking at tips here on discourse and on SO, I managed to get to this result :
As you can see, my translation file is loaded, but I have a message telling me that is cannot be loaded. Strange, isn’t it ? More than the strangeness of this, what bother me is that the application is not displayed anymore. Nothing. Blank page. No error, nothing. And if I remove all the modifications I made (see below), the application works again. It seems that this problem is what is causing the application to not being rendered.
Thanks for your help !
Here are the modifications that I made:
webpack.config.js
Added (in rules
):
{ test: /\.json$/i, use: 'json-loader', type: 'javascript/auto' },
Added (in new ModuleDependenciesPlugin
constructor):
'aurelia-i18n': [
{ name: 'locales/en/translation.json', chunk: 'i18n-en' },
{ name: 'locales/fr/translation.json', chunk: 'i18n-fr' }
]
Added (in plugins
):
new CopyWebpackPlugin([
{ from: 'src/locales/', to: 'locales/' }
//{ from: 'locales/', to: 'locales/' }
]),
main.ts
Added (in configure()
):
.plugin(PLATFORM.moduleName('aurelia-i18n'), (instance) => {
let aliases = ['t', 'i18n'];
// add aliases for 't' attribute
TCustomAttribute.configureAliases(aliases);
// register backend plugin
instance.i18next.use(Backend.with(aurelia.loader));
// adapt options to your needs (see http://i18next.com/docs/options/)
// make sure to return the promise of the setup method, in order to guarantee proper loading
return instance.setup({
backend: { // <-- configure backend settings
loadPath: 'locales/{{lng}}/{{ns}}.json', // <-- XHR settings for where to get the files from
},
attributes: aliases,
lng : 'fr',
fallbackLng : 'fr',
debug : true
});
})
New files
Added src/locales/en/translation.json
and src/locales/fr/translation.json
, both with the following content:
{
"score": "Score: {{score}}",
"lives": "{{count}} life remaining",
"lives_plural": "{{count}} lives remaining",
"friend": "A friend",
"friend_male": "A boyfriend",
"friend_female": "A girlfriend"
}