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

Configuration: defaultLanguage in TranslateModule.forRoot as a Provider #1476

Open
dbl81 opened this issue Mar 22, 2024 · 1 comment
Open

Comments

@dbl81
Copy link

dbl81 commented Mar 22, 2024

Current behavior

One of the configuration parameter for the TranslateModule.forRoot is the defaultLanguage parameter. Now it is a string value.

Expected behavior

Transform the defaultLanguage parameter into a provider so we can assign to it a value using for example a Factory.

What is the motivation / use case for changing the behavior?

In my application the value of the defaultLanguage is the result of a algorithm implemented by a function. Now I set the defaultLanguage in the main app component logic, but I think it's not a good practice to have initialization parameters in two different places, the main app component logic and the TranslateModule.forRoot.

Thank you.

How do you think that we should implement this?

@dbl81 dbl81 changed the title Configuration: defaultLanguage in TranslateModule.forRoot as a Factory Configuration: defaultLanguage in TranslateModule.forRoot as a Provider Mar 22, 2024
@cuddlecake
Copy link

Internally, default language is already an InjectionToken, see

{provide: DEFAULT_LANGUAGE, useValue: config.defaultLanguage},

So theoretically, you should be able to overwrite this provider, e.g.:

providers: [
  importProvidersFrom(TranslateModule.forRoot({ /* config */ }),
  { provide: DEFAULT_LANGUAGE, useFactory: defaultLanguageFactory },
]

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

2 participants