From cec4ee9cd8dcd9ee58b2ddfe08b77d6971b9dddb Mon Sep 17 00:00:00 2001 From: Evgeny Alaev Date: Thu, 25 Jan 2024 14:14:09 +0300 Subject: [PATCH] fix: use object properties instead strings in mapErrorCodeToMessage switch cases --- src/index.ts | 2 +- src/translation-helpers.ts | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index b749821..bb0f827 100644 --- a/src/index.ts +++ b/src/index.ts @@ -137,7 +137,7 @@ export class I18N { i18n(keysetName: string, key: string, params?: Params): string { if (!this.lang && !this.fallbackLang) { - throw new Error('There are no available languages. You should set at least one of these languages: lang, fallbackLang'); + throw new Error('Language not specified. You should set at least one of these: "lang", "fallbackLang"'); } let text: string | undefined; diff --git a/src/translation-helpers.ts b/src/translation-helpers.ts index 783de99..0d0a1e0 100644 --- a/src/translation-helpers.ts +++ b/src/translation-helpers.ts @@ -17,35 +17,35 @@ export function mapErrorCodeToMessage(args: {lang?: string; fallbackLang?: strin let message = ''; switch (code) { - case 'EMPTY_KEYSET': { + case ErrorCode.EmptyKeyset: { message = `Keyset is empty.`; break; } - case 'EMPTY_LANGUAGE_DATA': { + case ErrorCode.EmptyLanguageData: { message = 'Language data is empty.'; break; } - case 'KEYSET_NOT_FOUND': { + case ErrorCode.KeysetNotFound: { message = 'Keyset not found.'; break; } - case 'MISSING_KEY': { + case ErrorCode.MissingKey: { message = 'Missing key.'; break; } - case 'MISSING_KEY_FOR_0': { + case ErrorCode.MissingKeyFor0: { message = 'Missing key for 0'; break; } - case 'MISSING_KEY_PARAMS_COUNT': { + case ErrorCode.MissingKeyParamsCount: { message = 'Missing params.count for key.'; break; } - case 'MISSING_KEY_PLURALS': { + case ErrorCode.MissingKeyPlurals: { message = 'Missing required plurals'; break; } - case 'NO_LANGUAGE_DATA': { + case ErrorCode.NoLanguageData: { message = `Language "${lang}" is not defined, make sure you call setLang for the same language you called registerKeysets for!`; } }