Skip to content

Feature Request: Provide possibility to define custom locale imports for i18n builds #17752

@kyubisation

Description

@kyubisation

🚀 Feature request

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Description

Switzerland has four national languages ((swiss-)german, french, italian and romansh) and english as an official language. Switzerland however has no official locale specification, so as far as I know the CLDR data is just a "best effort" for specifying the locale.
For example the date format in en-CH is simply wrong (dd/MM/y should be dd.MM.y).
However there are also minor issues with the data; e.g. floating point numbers can be separated by both , or ., but . is more common. Also date and time are not usually separated by ,, but can be.

Since Angular and the Angular CLI limits the customization of locale information, this becomes a problem for the projects at SBB (national public transport provider), since the locales are specified by business for SBB projects.

Describe the solution you'd like

I would like to have a feature to provide our own locales, maybe with a warning for possible imcompatibility.

e.g.

      ...
      "i18n": {
        "locales": {
          "de-CH": {
            "translation": "src/i18n/messages.de-CH.xlf",
            "baseHref": "/de/",
            "localeImport": "example-library/locales/de-CH"
          },
          "fr-CH": {
            "translation": "src/i18n/messages.fr-CH.xlf",
            "baseHref": "/fr/",
            "localeImport": "example-library/locales/fr-CH"
          },
          "it-CH": {
            "translation": "src/i18n/messages.it-CH.xlf",
            "baseHref": "/it/",
            "localeImport": "example-library/locales/it-CH"
          }
        },
        "sourceLocale": {
          "code": "en-CH",
          "baseHref": "/en/",
          "localeImport": "example-library/locales/en-CH"
        }
        ...

This sould be doable, by changing configureI18nBuild in packages\angular_devkit\build_angular\src\utils\i18n-options.ts, so that it tries to resolve custom locale imports before calling findLocaleDataPath.
I'm also fine with printing a warning to point out possible incompatiblity issues.

If you are not opposed to this feature I can also provide a PR.

Describe alternatives you've considered

Either patch the locale data after startup or register all custom locales with registerlocaledata, which is cumbersome.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions