aurelia / i18n

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

Options on Backend init are overloaded with the default values. #282

Closed chabou-san closed 5 years ago

chabou-san commented 5 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: When specifying options for the backend at boot of the app using the following piece of code, options are not taken into account :

.plugin('aurelia-i18n', instance => {
[...]
  return instance.setup({
    backend: {
      loadPath: 'my/own/path/{{lng}}/{{ns}}.json'
    }
  });
}

Actually I found that during conversion to Typescript, this line, using the defaults function defined lines later in the same file, has been converted to Object.assign(). But arguments are not taken into account in the same order. As a result of this current use of Object.assign() , options are overloaded with the default values.

zewa666 commented 5 years ago

Yeah I think I see what happened here. Essentially the trouble was that the implementation of defaults was only updating if previously the property was undefined, thats why the order didn't really matter. So in this line merely switching the second with the third argument should get you rollin.

Can you try out the following please:

Backend.prototype.init = function (services, options) {
        if (options === void 0) { options = {}; }
        this.services = services;
        this.options = Object.assign({}, {
            loadPath: "/locales/{{lng}}/{{ns}}.json",
            addPath: "locales/add/{{lng}}/{{ns}}",
            allowMultiLoading: false,
            parse: JSON.parse
        }, options);
    };

note that options parameter is now at third position

After that try starting your app again and see whether this fixes your issue.

chabou-san commented 5 years ago

This is exactly what I did to fix the issue on my side and get going. I just didn't take the time to PR that change. So I can confirm it fixes it. 👍

zewa666 commented 5 years ago

Closing this as the fix was released in beta-2