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

All languages become the same #223

Open
bbesseling opened this issue Apr 21, 2021 · 1 comment
Open

All languages become the same #223

bbesseling opened this issue Apr 21, 2021 · 1 comment

Comments

@bbesseling
Copy link

If the first load of language strings is the following:

        var version = {
            "qi18n-appversion": "1.21.4.170",
        };
        $.i18n().load({
            "en": version,
            "nl": version,
        });

then it appears that the single "version" JavaScript object will be used to store additional strings for each language.
If you then load:

         $.i18n().load({
             "en": { "qi18n-foo": "foo" },
             "nl": { "qi18n-foo": "bar" }
         });

all translations of all languages "en" and "nl" of "qi18n-foo" end up coming out as "bar".
If you reverse the order of the two loads everything works fine, because the strings from "version" are then instead merged into each unique internal object for each language.
Ideally, the load function of the library should always create new empty internal objects for each new language internally and then merge any newly loaded strings into them from parameters, possibly from single "versions"-like objects.
Not terribly important except that it cost me a day to figure out why all my strings were always the "nl" version, no matter what locale I set. Reversing the order of the language strings in the loads made them all come out the "en" translation.

@Abhinob-Bora
Copy link

// Load version strings for each language
$.i18n().load({
"en": $.extend(true, {}, version), // Create a new object for "en"
"nl": $.extend(true, {}, version), // Create a new object for "nl"
});

I think this will solve the following issue becuase it will create a deep copy of the version object for each language, preventing the original version object from being modified during the loading process. This way, each language will have its own distinct set of strings.

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

No branches or pull requests

2 participants