Same interpolation object with multiple getFixedT() in different locales yields wrong translation #851

Closed
nielskrijger opened this Issue Dec 22, 2016 · 3 comments

Projects

None yet

2 participants

@nielskrijger
nielskrijger commented Dec 22, 2016 edited

Hi guys,

Thanks for the great library. I was using the old i18next and recently upgraded to the new version. Looks great! Much cleaner and better documented, love it.

I came across some unexpected behaviour; the following test setup demonstrates the issue:

const i18next = require('i18next');

i18next.init({
  lng: 'en',
  resources: {
    en: {
      translation: {
        key1: 'EN {{var}}'
      }
    },
    nl: {
      translation: {
        key1: 'NL {{var}}'
      }
    }
  }
}, (err, t) => {
  const english = i18next.getFixedT('en');
  const dutch = i18next.getFixedT('nl');

  // This prints "EN foo NL foo" as expected
  console.log(english('key1', { var: 'foo' }), dutch('key1', { var: 'foo' }));

  // This prints "EN foo EN foo", which is unexpected
  const interpolation = {
    var: 'foo'
  }
  console.log(english('key1', interpolation), dutch('key1', interpolation));
});

The behaviour surprised me and took some time to debug. I'm guessing some caching is going on somewhere. I'm not familair with the internals of i18next.

I uploaded the test setup here: https://github.com/nielskrijger/i18next-test

@nielskrijger nielskrijger changed the title from Identical interpolation object with getFixedT() yields wrong translation to Same interpolation object with multiple getFixedT() in different locales yields wrong translation Dec 22, 2016
@jamuhl
Member
jamuhl commented Dec 22, 2016

https://github.com/i18next/i18next/blob/master/src/i18next.js#L212

rather clear what's going wrong...bad me do mess with the options param...setting lng on it.

will be fixed asap and a patch version will be released...sorry for this.

@jamuhl jamuhl added the issue label Dec 22, 2016
@jamuhl jamuhl added a commit that closed this issue Dec 22, 2016
@jamuhl jamuhl fixed #851 f5ae680
@jamuhl jamuhl closed this in f5ae680 Dec 22, 2016
@jamuhl
Member
jamuhl commented Dec 22, 2016

should be fixed in i18next@4.1.2

@nielskrijger

Wow, that was fast.

Checked and works! Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment