locl icon indicating copy to clipboard operation
locl copied to clipboard

Support lazy load locale data at runtime

Open YZahringer opened this issue 4 years ago • 1 comments

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?

YZahringer avatar May 09 '20 14:05 YZahringer

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);

markpeterfejes avatar May 20 '20 10:05 markpeterfejes