wikimedia / jquery.i18n

🌐 jQuery based internationalization library
GNU General Public License v2.0
700 stars 143 forks source link

All languages become the same #223

Open bbesseling opened 3 years ago

bbesseling commented 3 years ago

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 commented 8 months ago

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