mirror of
https://github.com/tiennm99/github-readme-stats.git
synced 2026-05-24 10:24:57 +00:00
28 lines
580 B
JavaScript
28 lines
580 B
JavaScript
/**
|
|
* I18n translation class.
|
|
*/
|
|
class I18n {
|
|
constructor({ locale, translations }) {
|
|
this.locale = locale;
|
|
this.translations = translations;
|
|
this.fallbackLocale = "en";
|
|
}
|
|
|
|
t(str) {
|
|
const locale = this.locale || this.fallbackLocale;
|
|
|
|
if (!this.translations[str]) {
|
|
throw new Error(`${str} Translation string not found`);
|
|
}
|
|
|
|
if (!this.translations[str][locale]) {
|
|
throw new Error(`'${str}' translation not found for locale '${locale}'`);
|
|
}
|
|
|
|
return this.translations[str][locale];
|
|
}
|
|
}
|
|
|
|
export { I18n };
|
|
export default I18n;
|