aurelia / i18n

A plugin that provides i18n support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

config.attributes aliases do not get processed before aurelia global resources.

RichTeaTime opened this issue · comments

commented

I'm submitting a bug report

  • Library Version:
    1.6.1

Please tell us about your environment:

  • Operating System:
    Windows 8.1

  • Browser:
    all

  • Language:
    TypeScript 2.2.1

Current behavior:
If I register an alias for the 't' attribute during aurelia startup, e.g.
aurelia.plugin('aurelia-i18n', function (instance) { instance.setup({ attributes: ['i18n'], }); });

But also register (whether before or after, makes no difference), aurelia globalResources, e.g.
aurelia.globalResources([ 'mypath/mycomponent' ])

Then, usage of <div i18n="path.to.string'></div> does not work (t='path.to.string' does).
This is due to the framework.postTask(...) call that registers the aliases being executed after the postTask that loads and compiles the global resources.

Expected/desired behavior:
The aliases should be registered at the same time that the original 't' customattribute is registered, or at least, before user-specified global resources are compiled.

... created a Gist, but don't have a seperately bundled aurelia-i18n to include, add the registerPlugin('aurelia-i18n') to startup.js and it should work (not work).
https://gist.run/?id=52a97eb0320da10dabad1f3df3fb5d0b

  • What is the motivation / use case for changing the behavior?
    References to the aliases custom attribute are ignored in components added as globalResources, and their children.

Hi @RichTeaTime. Thats currently a known issue which I'm honestly not sure how to properly solve as it boils down to having the postTasks of plugins run later than the view parser for globalResources and features. In order to work around the issue you'd have to, as described in the docs, manually do the preregistration of the aliases

aurelia.use
  .standardConfiguration()
  .developmentLogging()
  .plugin('aurelia-i18n', (instance) => {
    let aliases = ['t', 'i18n'];
    
    TCustomAttribute.configureAliases(aliases); <----- THIS HERE
    
    // 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({...
    ...
commented

Thanks. That's perfect.