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; |