loclapp / locl

Internationalization (i18n) tools suite for Angular
https://www.locl.app
GNU Affero General Public License v3.0
92 stars 16 forks source link

Support lazy load locale data at runtime #31

Open YZahringer opened 4 years ago

YZahringer commented 4 years ago

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 commented 4 years ago

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