Files
github-readme-stats/src/common/I18n.js
T
Shivam Kotak 343058cc15 fix: adding doc strings to files in src folder where it was missing (#2129)
* fix: adding doc strings to files in src folder where it was missing

* refactor: add docstrings

* style: run formatter

Co-authored-by: rickstaa <rick.staa@outlook.com>
2022-10-07 16:22:02 +02:00

26 lines
562 B
JavaScript

/**
* I18n translation class.
*/
class I18n {
constructor({ locale, translations }) {
this.locale = locale;
this.translations = translations;
this.fallbackLocale = "en";
}
t(str) {
if (!this.translations[str]) {
throw new Error(`${str} Translation string not found`);
}
if (!this.translations[str][this.locale || this.fallbackLocale]) {
throw new Error(`${str} Translation locale not found`);
}
return this.translations[str][this.locale || this.fallbackLocale];
}
}
export { I18n };
export default I18n;