Skip to content

Commit

Permalink
fix: use object properties instead strings in mapErrorCodeToMessage s…
Browse files Browse the repository at this point in the history
…witch cases
  • Loading branch information
korvin89 committed Jan 25, 2024
1 parent bb07ff1 commit cec4ee9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/translation-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!`;
}
}
Expand Down

0 comments on commit cec4ee9

Please sign in to comment.