mirror of
https://github.com/tiennm99/github-readme-stats.git
synced 2026-05-27 16:23:06 +00:00
343058cc15
* 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>
26 lines
562 B
JavaScript
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;
|