Skip to content
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

fix(transloco): fixed error when inline loader for lang is not provided #760

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

adpawlik
Copy link

@adpawlik adpawlik commented Apr 23, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

If you use an inline loader and specify a language that is not included in the map, an error occurs.
e.g.

export const loader = ['en', 'es'].reduce((acc, lang) => {
    acc[lang] = () => import(`../i18n/${lang}.json`);
    return acc;
}, {});

export const FEATURE_ROUTES: Route = {
  path: 'feature',
  loadComponent: () => import('./feature.component').then(FeatureComponent => FeatureComponent),
  providers: [
    provideTranslocoScope({
      scope: 'scopeName',
      loader
    })
  ]
};

Issue Number: N/A

What is the new behavior?

The lack of a language in the given map does not cause the application to crash, it only logs an error in the case of the development version and loads a fallback language

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@shaharkazaz
Copy link
Collaborator

@adpawlik I'm not sure that crashing the app is the desired behavior here, why did you feel you needed to make this change?

@adpawlik
Copy link
Author

@shaharkazaz Because it is not good to throw an error at this point, because the "resolveLoader" function is used in transloco.service.ts and such an error will not be caught by catchError in rxjs, and therefore the fallback language will not be loaded.

Currently, all inline loaders must have map entries for each available language.

e.g.

//componentA 
export const loader = ['en', 'es'].reduce((acc, lang) => {
    acc[lang] = () => import(`../i18n/${lang}.json`);
    return acc;
}, {});

//componentB 
export const loader = ['en', 'es', 'de'].reduce((acc, lang) => {
    acc[lang] = () => import(`../i18n/${lang}.json`);
    return acc;
}, {});

If you try to load the 'de' language for componentA, it fails.

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

Successfully merging this pull request may close these issues.

None yet

3 participants