Skip to content

Verify all text nodes have an i18n attribute #44868

Open

Description

@dgp1130

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

@angular/compiler-cli

Description

In internationalized applications, each piece of text in an Angular template requires the i18n attribute. This can contain a description, and there are other i18n- attributes which provide localized versions of user-visible text (such as i18n-title). The attributes are easy to forget, especially edge cases like i18n-title. There should be some kind of conformance check which verifies that all text in an application is marked for internationalization.

Proposed solution

We could have an extended diagnostic which requires that every message in the compilation is marked for i18n and warns / errors for messages missing the relevant attribute. It could also warn on attributes like title and suggest i18n-title as an alternative.

Since not every app is internationalized, this check probably needs to be off by default, but having a one line config change like:

  {
    "angularCompilerOptions": {
      "extendedDiagnostics": {
        "checks": {
+         "i18nMessages": "error"
        }
      }
    }
  }

Would be a really easy way to make sure no messages fall through the cracks.

We may want some kind of i18n-ignore attribute to allow some messages to be skipped. I've seen this happen for debug UI which doesn't typically need to be translated.

Alternatives considered

There might be a community based solution which is able to do this, but I don't recall any offhand.

Activity

  1. added
    feature
    area: compiler
    on Jan 28, 2022
  2. added this to the Backlog milestone on Jan 28, 2022
  3. angular-robot commented on Jan 28, 2022

    @angular-robot
    Contributor

    This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

    You can find more details about the feature request process in our documentation.

  4. angular-robot commented on Mar 8, 2022

    @angular-robot
    Contributor

    Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends.

    Find more details about Angular's feature request process in our documentation.

  5. angular-robot commented on Mar 28, 2022

    @angular-robot
    Contributor

    Thank you for submitting your feature request! Looks like during the polling process it didn't collect a sufficient number of votes to move to the next stage.

    We want to keep Angular rich and ergonomic and at the same time be mindful about its scope and learning journey. If you think your request could live outside Angular's scope, we'd encourage you to collaborate with the community on publishing it as an open source package.

    You can find more details about the feature request process in our documentation.

  6. studioromeo commented on May 17, 2022

    @studioromeo

    It would be handy if the compiler could warn about using i18n when theres no static text to translate eg

    <span i18n>{{ title }}</span>

    Sometimes theres confusion on what i18n can pick up where people think it can determine all variations of title when actually it creates a translation like this

    <trans-unit id="187187500641108332" datatype="html">
      <source><x id="INTERPOLATION" equiv-text="{{ title }}"/></source>
      <context-group purpose="location">
        <context context-type="sourcefile">src/app/app.component.html</context>
        <context context-type="linenumber">1</context>
      </context-group>
    </trans-unit>

    Where the title is interpolated into the text and the title isn't localized.

    I guess a useful suggestion from the compiler could be to see if the user can add $localize to where title is defined but I also worry that could be confusing if title is a bit more complex than a simple title = 'Hello World'.

  7. Andrew-Marks-Trisept commented on Jun 3, 2022

    @Andrew-Marks-Trisept

    This would be fantastic, as long as (like you said), there is an easy way to override it for certain cases or false positives. And don't forget about messages defined in TS using $localize.

    Edit: I guess the ones that use $localize already are marked for translation. I guess there's probably no good way to make sure text from the TS files is translated...

  8. added
    feature: under consideration
    and removed on Sep 26, 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

    area: compilercompiler: extended diagnosticsfeaturefeature: under consideration

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions