Skip to content

Commit

Permalink
Merge pull request #598 from henrikhertler/move-does-not-exist-log
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Nov 27, 2023
2 parents 3fc33c1 + b0f56b7 commit da1e793
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/services/i18n.service.ts
Expand Up @@ -88,37 +88,27 @@ export class I18nService<K = Record<string, unknown>>

const previousFallbackLang = lang;

lang =
lang === undefined || lang === null
? this.i18nOptions.fallbackLanguage
: lang;
lang = lang ?? this.i18nOptions.fallbackLanguage;

lang = this.resolveLanguage(lang);

const translationsByLanguage = this.translations[lang];

const translation = this.translateObject(
key as string,
(translationsByLanguage ? translationsByLanguage : key) as string,
(translationsByLanguage ?? key) as string,
lang,
options,
translationsByLanguage ? translationsByLanguage : undefined,
translationsByLanguage,
);

if (
translationsByLanguage === undefined ||
translationsByLanguage === null ||
!translation
) {
if (translationsByLanguage == null || !translation) {
const translationKeyMissing = `Translation "${
key as string
}" in "${lang}" does not exist.`;
if (lang !== this.i18nOptions.fallbackLanguage || !!defaultValue) {
if (this.i18nOptions.logging) {
const message = `Translation "${
key as string
}" in "${lang}" does not exist.`;
this.logger.error(message);
if (this.i18nOptions.throwOnMissingKey) {
throw new I18nError(message);
}
if (this.i18nOptions.logging && this.i18nOptions.throwOnMissingKey) {
throw new I18nError(translationKeyMissing);
}

const nextFallbackLanguage = this.getFallbackLanguage(lang);
Expand All @@ -130,6 +120,8 @@ export class I18nService<K = Record<string, unknown>>
});
}
}

this.logger.error(translationKeyMissing);
}

return (translation ?? key) as unknown as IfAnyOrNever<R, string, R>;
Expand Down

0 comments on commit da1e793

Please sign in to comment.