Skip to content

Multi-locale Ivy builds do not use registerLocaleData #15974

@filipesilva

Description

@filipesilva

localeData, obtained via @angular/common/locales/<locale>, is needed for several FW features like pluralization.

In VE each build resulted in a single locale. To register the locale data in VE the CLI added the following code via a transform:

import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
registerLocaleData(localeFr, 'fr');

Locales can also have extra information that the CLI did not handle. It would have required to use add the code below instead:

import { registerLocaleData } from '@angular/common';
import localeFr from '@angular/common/locales/fr';
import localeFrExtra from '@angular/common/locales/extra/fr';
registerLocaleData(localeFr, 'fr-FR', localeFrExtra);

In Ivy each build can result in several locales. To use a similar mechanism would look like this:

import {registerLocaleData} from '@angular/common';
import localeFr from '@angular/common/locales/fr';
import localeDe from '@angular/common/locales/de';
switch ($localize.locale) {
  case 'fr':
    registerLocaleData(localeFr);
    break;
  case 'de':    
    registerLocaleData(localeDe);
  default:
    break;
}

This approach is not ideal because all locale-specific builds would include all locale data.

Since localize operates after code is built and bundled, introducing locale specific data presents a novel problem.

A repro of this problem can be found in https://github.com/filipesilva/i18n. It is still possible to do individual locale builds (via the i18n* options) with Ivy though.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions