Skip to content

Update i18n doc with loadTranslations and $localize #37563

Closed

Description

@rockument69

📚 Docs or angular.io bug report

Description

Issue first reported in #35776.
Related issue about length of document: #33461

Developers want the following:

Please add docs for loadTranslations and clearTranslations.
Use i18n for library in ng-packagr.

🔬 Minimal Reproduction

What's the affected URL?**

https://angular.io/guide/i18n#internationalization-i18n

Reproduction Steps**

Expected vs Actual Behavior**

Some of this content requires a description of $localize, which is not a public API yet.

Doc team wants to separate the i18n doc into 3 separate docs:

Task: Translating templates for different locales

  • Format data based on locale using pipes
  • Prepare templates for translations
  • Extract and work with translation files
  • Mark plurals and alternates for translation
  • Translate plurals and alternate expressions
  • See comment in PR about ICU expressions

Task: Localizing your app

  • Set up localization
  • Merge translations with the app
  • Inline at compile-time
  • Runtime ?
  • Merge translated libraries used in the app
  • Deploy app for multiple locales

Tutorial: Using $localize in your app

  • Step-by-step tutorial

Other docs that need updating:

For details, see the i18n Documentation Plan.

📷Screenshot

🔥 Exception or Error





🌍 Your Environment

Browser info

Anything else relevant?

Activity

  1. self-assigned this
    on Jun 12, 2020
  2. modified the milestone: needsTriage on Jun 12, 2020
  3. modified the milestones: needsTriage, Backlog on Sep 17, 2020
  4. stefan-schweiger commented on Feb 11, 2021

    @stefan-schweiger

    What I'm having a really hard time to understand is if it's ok to use $localize.locale or if we are supposed to keep using the injected LOCALE_ID since it's never mentioned anywhere.

    I think soluing (no affiliation) has a pretty good doc on a i18n and a few $localize functionalities. But I would prefer an official doc to know what's actually a supported functionality.

  5. petebacondarwin commented on Feb 11, 2021

    @petebacondarwin
    Contributor

    $localize.locale is only available if you are using runtime translation of $localize. So if you are using compile time inlining of translations then $localize.localize will not exist. You should be able to rely upon the LOCALE_ID injectable. The Angular CLI automatically includes the locale data and sets the LOCALE_ID value when you use the --localize option with ng build.

  6. stefan-schweiger commented on Feb 11, 2021

    @stefan-schweiger

    @petebacondarwin At least in Angular 10.0 $localzie.locale works during compile time translation as it gets replaced with a string of the locale (e.g. "de").

    It's not accessible during runtime with ng serve for whatever reason ($localize has a function value), but with ng build you can also access it during runtime.

    This is what I meant when I said, the documentation is lacking and the usage is confusing 😅

  7. stefan-schweiger commented on Feb 12, 2021

    @stefan-schweiger

    @petebacondarwin it's also working with Angular 11 as you can see in this repro https://github.com/stefan-schweiger/angular-localize-test

    It doesn't work on stackblitz (I guess they are using some special build configurations) but when you run it locally via ng serve or ng build (even with AOT) you get the right values for $localize.locale in the .ts files, but it fails in the template files. But even then you can just set it to a property from the code and it works, so it's not that different to using LOCALE_ID.

    So is this an official function and legitimate use case or not?

  8. petebacondarwin commented on Feb 12, 2021

    @petebacondarwin
    Contributor

    $localize.locale works during compile time translation as it gets replaced with a string of the locale (e.g. "de").

    Oh yes! I have forgotten that the CLI also does this.

  9. petebacondarwin commented on Feb 12, 2021

    @petebacondarwin
    Contributor

    You cannot access any globals in templates (except for null) and so it is expected that {{ $localize.locale }} would not work. It is not related to $localize itself.

  10. petebacondarwin commented on Feb 12, 2021

    @petebacondarwin
    Contributor

    You are basically right in your first description of this issue. This whole area is not documented well (or at all).
    Hopefully #40317 will begin to resolve this. But we do need to add more to the guides.

  11. removed their assignment
    on May 21, 2021
  12. michaelfaith commented on Jul 24, 2021

    @michaelfaith

    Would love to have more documentation on this. Especially handling runtime localization and about building libraries with translations.

  13. modified the milestones: Backlog, needsTriage on Nov 28, 2021
  14. jessicajaniuk commented on Dec 13, 2021

    @jessicajaniuk
    Contributor

    Thanks for reporting this issue. This issue is now obsolete due to changes in the recent releases. Please update to the most recent Angular version.

    If the problem still exists in your application, please open a new issue and follow the instructions in the issue template.

  15. angular-automatic-lock-bot commented on Jan 13, 2022

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  16. locked and limited conversation to collaborators on Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions