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

Feature(Docs): Another way for preloading languages to discuss #752

Open
thekhegay opened this issue Mar 1, 2024 · 0 comments
Open

Feature(Docs): Another way for preloading languages to discuss #752

thekhegay opened this issue Mar 1, 2024 · 0 comments

Comments

@thekhegay
Copy link

thekhegay commented Mar 1, 2024

First way: Prefetch the User Language
Second way: Preload Languages

New way:

import { APP_INITIALIZER, Provider } from '@angular/core';
import { forkJoin, lastValueFrom } from 'rxjs';

import { TranslocoService } from '@ngneat/transloco';

function translocoPreloadFactory(translocoService: TranslocoService) {
  return () => {
    const call = ['en', 'es'].reduce(
      (o, lang) => ({
        ...o,
        [lang]: translocoService.load(lang),
      }),
      {}
    );
    return lastValueFrom(forkJoin(call));
  };
}

export const providePreloadTransloco: Provider = {
  provide: APP_INITIALIZER,
  useFactory: translocoPreloadFactory,
  deps: [TranslocoService],
  multi: true,
};
@thekhegay thekhegay changed the title Feature(Docs): Another way for preload langs Feature(Docs): Another way for preloading languages to discuess Mar 1, 2024
@thekhegay thekhegay changed the title Feature(Docs): Another way for preloading languages to discuess Feature(Docs): Another way for preloading languages to discuss Mar 1, 2024
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