mirror of
https://github.com/tiennm99/github-readme-stats.git
synced 2026-07-30 18:22:53 +00:00
feat: card locale translations (#509)
* Add Card Translations * Add tests and documentation for `?lang` option * Card Translations: update Italian * Run Prettier * Correct German Translations. Co-authored-by: schmelto <30869493+schmelto@users.noreply.github.com> * refactor: added i18n class to manage translation logic & improved code * Make the new src/translations.js more concise * Update translations.js Co-authored-by: schmelto <30869493+schmelto@users.noreply.github.com> * Revert 4175484d69289e4ee7283ab968b8e71c3c5d77df * fix: overlap because of language length Co-authored-by: lrusso96 <russo.1699981@studenti.uniroma1.it> Co-authored-by: schmelto <30869493+schmelto@users.noreply.github.com> Co-authored-by: Anurag <hazru.anurag@gmail.com>
This commit is contained in:
co-authored by
lrusso96
schmelto
Anurag
parent
2707d07453
commit
f1df178643
@@ -0,0 +1,21 @@
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = I18n;
|
||||
@@ -188,6 +188,12 @@ class CustomError extends Error {
|
||||
static USER_NOT_FOUND = "USER_NOT_FOUND";
|
||||
}
|
||||
|
||||
function isLocaleAvailable(locale) {
|
||||
return ["cn", "de", "en", "es", "fr", "it", "ja", "kr", "pt-br"].includes(
|
||||
locale.toLowerCase(),
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
renderError,
|
||||
kFormatter,
|
||||
@@ -201,6 +207,7 @@ module.exports = {
|
||||
getCardColors,
|
||||
clampValue,
|
||||
wrapTextMultiline,
|
||||
isLocaleAvailable,
|
||||
logger,
|
||||
CONSTANTS,
|
||||
CustomError,
|
||||
|
||||
Reference in New Issue
Block a user