Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context and nested lost initial options #1009

Closed
fram03 opened this issue Dec 28, 2017 · 2 comments
Closed

Context and nested lost initial options #1009

fram03 opened this issue Dec 28, 2017 · 2 comments

Comments

@fram03
Copy link
Contributor

fram03 commented Dec 28, 2017

Hi, I'm updating i18next version in my project from a prehistoric 1.7 to the last 10.2.1.
The only problem encountered is about context and nest.
If I specify a context in a resource value initial options will be lost in the nested translations.
Is there a param to force this behaviour?

var i18n = require("i18next")
i18n.init({
    'lng': 'en',
    'compatibilityJSON': 'v1',
    'resources': {
        'en': {
            'translation': {
                "withContext_A": "hello world from __name__ - A",
                "withContext": "hello world from __name__ - B",
                "start": "Start string $t(withContext, {'context': '__test__'})",
                "startClean": "Start string $t(withContext)"
            }
        }
    },
    'interpolation': {
        'escapeValue': false,
        'prefix': '__',
        'suffix': '__'
    }
}, function() {
    // Expected "Start string hello world from John - A"  (as in 1.7)
    // but I'm receiving "Start string hello world from - A"
    console.log('TEST1', i18n.t('start', {'test': 'A', 'name': 'John'}));  
   // Expected "Start string hello world from John - B" and it's ok
    console.log('TEST2', i18n.t('startClean', {'test': 'A', 'name': 'John'}));
});
@jamuhl
Copy link
Member

jamuhl commented Dec 28, 2017

when doing nest and you pass in options like "Start string $t(withContext, {'context': '__test__'})" it only takes this options in the string not the one passed in, cause of:

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

a) change it to: "Start string $t(withContext, {'context': '__test__', 'name': '__name__'})"
b) provide a PR cloning those options back into the clonedOptions

fram03 added a commit to fram03/i18next that referenced this issue Dec 29, 2017
nested translations inherit parent's options
@jamuhl
Copy link
Member

jamuhl commented Dec 29, 2017

published in [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants