Skip to content

Bug(transloco): transloco loader trigger 2 times on scoped translation #625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
Yberion opened this issue Feb 11, 2023 · 0 comments
Open
1 task done

Comments

@Yberion
Copy link

Yberion commented Feb 11, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Which Transloco package(s) are the source of the bug?

Transloco

Is this a regression?

No (no idea)

Current behavior

When navigating to a page with a scoped translation, it trigger 2 times the loader:

image

useFallbackTranslation is set to true and both defaultLang and fallbackLang has the same value.

I also suspect another bug, all translation keys are fine on this scoped component, I don't get why it's loading the fallback lang file as there's no error.

Both problem only appear with the scoped translation, it works as expected for the main file.

Expected behavior

If the current lang is the same as the fallbackLang, then it should not load the fallback file as it will already be loaded by default.

If there is no translation error, it should not load the fallback lang file.

Please provide a link to a minimal reproduction of the bug

https://github.com/ngneat/transloco/tree/master/apps/transloco-playground

Change fallbackLang to en, set useFallbackTranslation to true and navigate to the scoped route:

https://github.com/ngneat/transloco/blob/master/apps/transloco-playground/src/app/transloco-root.module.ts#L45-L48

Transloco Config

{
  provide: TRANSLOCO_CONFIG,
  useValue: translocoConfig({
    availableLangs: ['fr-FR', 'en-GB'],
    defaultLang: 'fr-FR',
    fallbackLang: 'fr-FR',
    // Remove this option if your application doesn't support changing language in runtime.
    reRenderOnLangChange: true,
    prodMode: !isDevMode(),
    missingHandler: {
      useFallbackTranslation: true,
    },
  }),
},

Please provide the environment you discovered this bug in

Transloco: 4.2.2
Angular: 15.1.5
Node: 18.13.0
Package Manager: pnpm@7.27.0
Typescript: 4.9.5
OS: Windows 11 22H2

Browser

No response

I would like to make a pull request for this bug

Yes 🚀

@Yberion Yberion changed the title Bug(transloco): transloco loader triggers 2 times on scope translation Bug(transloco): transloco loader trigger 2 times on scoped translation Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant