Skip to content

Commit

Permalink
fix: double-check missing translation before reporting (#728)
Browse files Browse the repository at this point in the history
Closes #726
  • Loading branch information
dhhyi authored Jun 15, 2021
1 parent 0df6e8d commit f1eb525
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ export class FallbackMissingTranslationHandler implements MissingTranslationHand

handle(params: MissingTranslationHandlerParams) {
if (params.interpolateParams || /^\w+(\.[\w-]+)+$/.test(params.key)) {
this.reportMissingTranslation(params.translateService.currentLang, params.key);
const currentLang = params.translateService.currentLang;
/*
* when changing languages 'currentLang' from the translate service
* is out of sync -- double check before reporting
*/
if (!params.translateService.translations?.[currentLang]?.[params.key]) {
this.reportMissingTranslation(currentLang, params.key);
}

const doSingleCheck = isPlatformBrowser(this.platformId) && /\berror\b/.test(params.key);
const isFallbackAvailable = params.translateService.currentLang !== this.fallback;
const isFallbackAvailable = currentLang !== this.fallback;
return concat(
// try API call with specific key
iif(() => doSingleCheck, this.retrieveSpecificTranslation(params.translateService.currentLang, params.key)),
iif(() => doSingleCheck, this.retrieveSpecificTranslation(currentLang, params.key)),
// try fallback translations
iif(
() => isFallbackAvailable,
Expand Down

0 comments on commit f1eb525

Please sign in to comment.