/
githubmirror
/
github-readme-stats
Обзор
Документация
Войти
/
githubmirror
/
github-readme-stats
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/common/I18n.js
43 строки
886 B
Alexandr Garbuzov
fix: resolve vscode type errors inside I18n class (#4605)
19 окт 2025, 23:51
Не верифицирован
19 окт 2025, 23:51
5de1aa8
Код
Авторство
О чём код?
// @ts-check const FALLBACK_LOCALE = "en"; /** * I18n translation class. */ class I18n { /** * Constructor. * * @param {Object} options Options. * @param {string=} options.locale Locale. * @param {any} options.translations Translations. */ constructor({ locale, translations }) { this.locale = locale || FALLBACK_LOCALE; this.translations = translations; } /** * Get translation. * * @param {string} str String to translate. * @returns {string} Translated string. */ t(str) { if (!this.translations[str]) { throw new Error(`${str} Translation string not found`); } if (!this.translations[str][this.locale]) { throw new Error( `'${str}' translation not found for locale '${this.locale}'`, ); } return this.translations[str][this.locale]; } } export { I18n }; export default I18n;