TAPevents / tap-i18n

A comprehensive internationalization solution for Meteor.
MIT License
329 stars 86 forks source link

Embedded strings don't switch when switching a language on Android #216

Closed MastaBaba closed 11 months ago

MastaBaba commented 5 years ago

I'm using tap:i18n in a Meteor project. It works fine. Except not on Android.

When, on localhost, or after deploying to an iOS app, I switch languages, all is well.

When deploying to Android, the language switch fails.

I've got this as my language switch function:

TAPi18n.setLanguage(getUserLanguage())
.done(function () {
    Session.set("showLoadingIndicator", false);
    alert("Language is now " + getUserLanguage());
})
.fail(function (error_message) {
    // Handle the situation
    console.log(error_message);

    alert("Could not set language to " + getUserLanguage());
    alert(error_message);
});

The error message is this:

Couldn't load language 'pt' JSON: error

The pt language file (pt.i18n) is this:

{ }

Yes, that language file is empty. It wasn't before, so I figured something was preventing the JSON from being read properly. But, apparently, using an empty JSON string didn't change anything.

I'm using version 1.8.2 of tap:i18n with Meteor 1.8.1, on Android 9.

What could be the cause? How to resolve this?

MastaBaba commented 5 years ago

I resolved this by removing tap:i18n, replacing it with my own translation function. Like so:

Template.registerHelper('_', function(reference) {
    var strings = [];

    strings["en"] = { 
    "identifier_1": "string 1 in English",
        ...
}
    strings["pt"] = { 
    "identifier_1": "string 1 in Portuguese.",
        ...
}

    var language = getSetting("language");

    return strings[language][reference];
})