aurelia / i18n

A plugin that provides i18n support.
MIT License
93 stars 70 forks source link

i18n params attribute doesn't work in globally registered custom elements #305

Open peitschie opened 5 years ago

peitschie commented 5 years ago

I'm submitting a bug report

Current behavior: image Repro code at https://github.com/peitschie/bug-repro-aurelia-i18n-alias. This is somewhat similar to #206.

In this screenshot, the first two lines show i18n parameter binding working for both non-aliased (t-params.bind) and aliased (i18n-params.bind) bindings. These are then copied into a global resource, where it can be seen that the aliased binding (i18n-params.bind) does not function, hence the blank space on the 3rd line.

Expected/desired behavior: I am expecting all these combinations to behave identically.

zewa666 commented 5 years ago

Thx for the repro I'll take a look. Clearly it looks like a bug as I cant see anything wrong in the sample

zewa666 commented 5 years ago

I think I found the issue, yet I don't really know why it happens.

In your main.ts, if you comment out the following:

// .feature(PLATFORM.moduleName('resources/index'))
// .globalResources(PLATFORM.moduleName('resources/message/message'));

and instead require the message custom element right before it's use

<require from="./resources/message/message"></require>
<message></message>

all seems to work. So it must be a timing issue with registration, as that the features are registered before the plugin so we're too late to the story.

khuongduybui commented 4 years ago

I tried to fix the "timing issue with registration" as following but could not fix the issue.

export function configure(aurelia: Aurelia) {
  aurelia.use.standardConfiguration();

  aurelia.use.plugin('aurelia-i18n', (plugin) => {
    // ...
  });

  aurelia.use.feature('resources');
  // ...
}
bigopon commented 4 years ago

Doing the following:

    .feature(PLATFORM.moduleName('resources/index'))
    .plugin(PLATFORM.moduleName('aurelia-i18n'), (instance: any) => {

means load all resources inside resources/index and then load aurelia-i18n. Which means any resources loaded before i18n will have their template parsed without the knowledge of aurelia-i18n attributes, value converters, binding behaviors. I think this can simply be solved by ensuring this plugin will be registered before any app resources:

    .plugin(PLATFORM.moduleName('aurelia-i18n'), (instance: any) => {/*....*/})
    ...
    .feature(PLATFORM.moduleName('resources/index'))
zewa666 commented 4 years ago

Nope not going to work since i18n is lazily initialized via callback

khuongduybui commented 4 years ago

Nope not going to work since i18n is lazily initialized via callback

Can we force it to behave differently?