forked from mirrored/github-readme-stats
* GRS-1955: Using ES6 import/export in src files * GRS-1955: Using ES6 import/export in test files * GRS-1955: Using ES6 import/export in themes index.js * GRS-1955: Readding blank line at end of top-languages-card.js * feat: fix test es6 import errors This commit makes sure jest is set-up to support es6. It also fixes several test errors and sorts the imports. * test: update test node version This commit makes sure node 16 is used in the github actions. * refactor: run prettier Co-authored-by: rickstaa <rick.staa@outlook.com>
23 lines
527 B
JavaScript
23 lines
527 B
JavaScript
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;
|