8000 Add doc section for runtime translations in internationalization guide · Issue #46851 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content
Add doc section for runtime translations in internationalization guide #46851
Open
@TheSlimvReal

Description

@TheSlimvReal

Which @angular/* package(s) are relevant/related to the feature request?

localize

Description

There are various issues and StackOverflow posts around the question how runtime translations are possible in Angular (#38953, #46783 ...). After a lot of digging around I was actually able to get all the requirements for runtime translations running using all the things Angular offers. So it is really just the poor documentation that takes a lot of time on debugging and finding the right functions.

Therefore, I suggest to add a section to the Internationalization guide under Optional internationalization practices.

Proposed solution

In this guide I would cover the following things:

  1. Describe pros and cons of runtime translations (why would someone want that)
  2. Explain the necessary functions/variables (loadTranslations, $localize.locale, registerLocaleData, LOCALE_ID)
  3. Describe the required format of the JSON file for loadTranslations and potentially a script to parse xliff to JSON
  4. Show a minimal/simple setup for the main.ts and app.module.ts for the right initialization
    1. Read locale from LocalStorage
    2. Load the translation file using fetch
    3. Call loadTranslations and init $localize.locale
    4. Show how to lazy load only the required locale from @angular/common/locales/ using webpack
    5. Call registerLocaleData
    6. Bootstrap app by dynamically importing AppModule after loading translations to also translate static variables (see here)
    7. Set LOCALE_ID in AppModule
  5. Some further considerations

I am happy to create a PR for this guide as soon as somebody from the Angular team gives me green light for it.

Alternatives considered

We could also extends the documentations for loadTranslation and registerLocaleData but then the developers still need to find out that these functions even exist.

Metadata

Metadata

Assignees

Labels

P4A relatively minor issue that is not relevant to core functionsarea: docsRelated to the documentationarea: i18nIssues related to localization and internationalization

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0