tflori / angular-translator

translation module for angular
https://tflori.github.io/angular-translator/
MIT License
21 stars 6 forks source link

Fallbacks if the key could not be resolved #74

Closed javix closed 5 years ago

javix commented 5 years ago

Hi, it is possible to implement some fallbacks if a key could not be resolved? The following logic would be conceivable:

Put this code to Translator instant function before line 263:

var t;
if (!this.translations[language] || !this.translations[language][key]) {
    this.logHandler.info(this.generateMessage("missing", { key: key, language: language }));
    if (language === this.config.defaultLanguage) {
        // This key is not available in the default language     
        return key;
    }
    else {
        // Use default language to translate the key
        t = this.instant(key, params, this.config.defaultLanguage);
    }
}
else {
    t = this.translations[language][key];
}
tflori commented 5 years ago

makes sense - especially when using keys that don't read well. feel free to open a MR.

javix commented 5 years ago

Done. I hope everything fits.

javix commented 5 years ago

Oh, I see: "Coverage decreased". I try to complete the tests.

tflori commented 5 years ago

@javix thx for your contribution