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

Support lazy load locale data at runtime #31

Open
YZahringer opened this issue May 9, 2020 · 1 comment
Open

Support lazy load locale data at runtime #31

YZahringer opened this issue May 9, 2020 · 1 comment
Labels
enhancement New feature or request @locl/core

Comments

@YZahringer
Copy link

It would be useful to be able to load the locale data at bootstrap at the same time of translations.

The solution documented here could be integrated/supported by locl? A better solution is now available with Angular 9 and $localize?

@markpeterfejes
Copy link

markpeterfejes commented May 20, 2020

Does this code snippet help you?

import { registerLocaleData } from '@angular/common';

/**
 * Load the appropriate locale
 */
async function initializeLocale(localeId: string): Promise<void> {
  return import(
    /* webpackMode: "lazy-once" */
    `@angular/common/locales/${localeId}.js`
  ).then((localeModule) => registerLocaleData(localeModule.default));
}

Then you can call it where you load the translations with locl:

await initializeLocale(translations.locale);

@ocombe ocombe added enhancement New feature or request @locl/core labels May 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request @locl/core
Projects
None yet
Development

No branches or pull requests

3 participants