diff --git a/src/index.ts b/src/index.ts index 96c5a39..b749821 100644 --- a/src/index.ts +++ b/src/index.ts @@ -146,7 +146,7 @@ export class I18N { ({text, fallbackText, details} = this.getTranslationData({keysetName, key, params, lang: this.lang})); - if (details && details.code !== ErrorCode.NO_LANGUAGE_DATA) { + if (details && details.code !== ErrorCode.NoLanguageData) { const message = mapErrorCodeToMessage({ code: details.code, lang: this.lang, @@ -163,7 +163,7 @@ export class I18N { lang: this.fallbackLang, })); - if (details && details.code !== ErrorCode.NO_LANGUAGE_DATA) { + if (details && details.code !== ErrorCode.NoLanguageData) { const message = mapErrorCodeToMessage({ code: details.code, lang: this.lang, @@ -236,13 +236,13 @@ export class I18N { const languageData = this.getLanguageData(lang); if (typeof languageData === 'undefined') { - return {details: {code: ErrorCode.NO_LANGUAGE_DATA}}; + return {details: {code: ErrorCode.NoLanguageData}}; } if (Object.keys(languageData).length === 0) { return { fallbackText: key, - details: {code: ErrorCode.EMPTY_LANGUAGE_DATA}, + details: {code: ErrorCode.EmptyLanguageData}, }; } @@ -251,14 +251,14 @@ export class I18N { if (!keyset) { return { fallbackText: key, - details: {code: ErrorCode.KEYSET_NOT_FOUND, keysetName}, + details: {code: ErrorCode.KeysetNotFound, keysetName}, }; } if (Object.keys(keyset).length === 0) { return { fallbackText: key, - details: {code: ErrorCode.EMPTY_KEYSET, keysetName}, + details: {code: ErrorCode.EmptyKeyset, keysetName}, }; } @@ -268,7 +268,7 @@ export class I18N { if (typeof keyValue === 'undefined') { return { fallbackText: key, - details: {code: ErrorCode.MISSING_KEY, keysetName, key}, + details: {code: ErrorCode.MissingKey, keysetName, key}, }; } @@ -276,7 +276,7 @@ export class I18N { if (keyValue.length < 3) { return { fallbackText: key, - details: {code: ErrorCode.MISSING_REQUIRED_PLURALS, keysetName, key}, + details: {code: ErrorCode.MissingKeyPlurals, keysetName, key}, }; } @@ -285,7 +285,7 @@ export class I18N { if (Number.isNaN(count)) { return { fallbackText: key, - details: {code: ErrorCode.MISSING_KEY_PARAMS_COUNT, keysetName, key}, + details: {code: ErrorCode.MissingKeyParamsCount, keysetName, key}, }; } @@ -294,7 +294,7 @@ export class I18N { if (keyValue[PluralForm.None] === undefined) { result.details = { - code: ErrorCode.MISSING_KEY_FOR_0, + code: ErrorCode.MissingKeyFor0, keysetName, key, }; diff --git a/src/translation-helpers.ts b/src/translation-helpers.ts index 5ec655a..783de99 100644 --- a/src/translation-helpers.ts +++ b/src/translation-helpers.ts @@ -1,12 +1,12 @@ export const ErrorCode = { - NO_LANGUAGE_DATA: 'NO_LANGUAGE_DATA', - EMPTY_LANGUAGE_DATA: 'EMPTY_LANGUAGE_DATA', - KEYSET_NOT_FOUND: 'KEYSET_NOT_FOUND', - EMPTY_KEYSET: 'EMPTY_KEYSET', - MISSING_KEY: 'MISSING_KEY', - MISSING_REQUIRED_PLURALS: 'MISSING_REQUIRED_PLURALS', - MISSING_KEY_PARAMS_COUNT: 'MISSING_KEY_PARAMS_COUNT', - MISSING_KEY_FOR_0: 'MISSING_KEY_FOR_0', + EmptyKeyset: 'EMPTY_KEYSET', + EmptyLanguageData: 'EMPTY_LANGUAGE_DATA', + KeysetNotFound: 'KEYSET_NOT_FOUND', + MissingKey: 'MISSING_KEY', + MissingKeyFor0: 'MISSING_KEY_FOR_0', + MissingKeyParamsCount: 'MISSING_KEY_PARAMS_COUNT', + MissingKeyPlurals: 'MISSING_KEY_PLURALS', + NoLanguageData: 'NO_LANGUAGE_DATA', } as const; const codeValues = Object.values(ErrorCode); @@ -41,7 +41,7 @@ export function mapErrorCodeToMessage(args: {lang?: string; fallbackLang?: strin message = 'Missing params.count for key.'; break; } - case 'MISSING_REQUIRED_PLURALS': { + case 'MISSING_KEY_PLURALS': { message = 'Missing required plurals'; break; }