aurelia / i18n

A plugin that provides i18n support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Options on Backend init are overloaded with the default values.

chabou-san opened this issue · comments

I'm submitting a bug report

  • Library Version:
    3.0.0-beta.1

Please tell us about your environment:

  • Operating System:
    OSX 10.x

  • Node Version:
    8.11.4

  • NPM Version:
    5.6.0

  • JSPM OR Webpack AND Version
    webpack 4.17.2

  • Browser:
    all

  • Language:
    all

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'
    }
  });
}
  • What is the expected behavior?
    Options provided by the user shall be taken into account.

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.

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:

  • In your sample open up node_modules/aurelia-i18n/dist/native-modules/aurelia-i18n-loader.js
  • On line 48, switch the two parameters, so that it reads
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.

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. 👍

Closing this as the fix was released in beta-2