All files / i18n-react-json index.js

100% Statements 8/8
100% Branches 6/6
100% Functions 3/3
100% Lines 6/6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21        9x       6x 5x 4x 4x       6x          
import _ from "lodash";
 
class Translate {
  constructor(translations) {
    this.translations = translations;
  }
 
  __(text) {
    if (_.isNil(this.language)) return text;
    if (_.isNil(this.translations[this.language])) return text;
    const translation = this.translations[this.language];
    return !_.isNil(translation[text]) ? translation[text] : text;
  }
 
  setLocale(language) {
    this.language = language;
  }
}
 
export default Translate;