Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n best practices #377

Closed
2 tasks done
mgechev opened this issue Jul 13, 2017 · 6 comments
Closed
2 tasks done

i18n best practices #377

mgechev opened this issue Jul 13, 2017 · 6 comments

Comments

@mgechev
Copy link
Owner

mgechev commented Jul 13, 2017

Consider to add the following i18n best practice:

Set a custom id to improve search and maintenance

The angular i18n extractor tool generates a file with a translation unit entry for each i18n attribute in a template. By default, it assigns each translation unit a unique id such as this one:

content_copy

This id is obscure and difficult for humans to read or remember.

Worse, when you change the translatable text, perhaps to fix a typo, the extractor tool generates a new id for that translation. You will lose the translation unless you update it with the new id. That complicates maintenance.

  • - Look for elements without custom ID.
  • - Look for elements with text content but no i18n attribute.

https://angular.io/guide/i18n#set-a-custom-id-to-improve-search-and-maintenance

@abierbaum
Copy link

Would it be possible to also add a rule that looks for elements in component templates that have text content but no i18n attribute?

One issue we are having on our team is simply enforcing that people mark all the exposed strings for extraction and translation.

@mgechev
Copy link
Owner Author

mgechev commented Jul 26, 2017

This should be relatively straightforward. I will add it as part of this issue.

@abierbaum
Copy link

@mgechev Awesome. Thanks!!!

@mgechev mgechev added this to the 3.2.0 - Grace Hopper milestone Jul 26, 2017
@mgechev mgechev self-assigned this Jul 26, 2017
@mgechev
Copy link
Owner Author

mgechev commented Aug 2, 2017

@abierbaum both rules are implemented in #386. Should be ready to use in codelyzer@3.2.0.

@panuruj
Copy link

panuruj commented Aug 5, 2017

In general, I would not recommend overriding the auto-generated ID. In a project that have thousands of strings to be translated, it is error prone to rely on the developer to ensure that the ID is unique across the entire application.

mgechev added a commit that referenced this issue Aug 5, 2017
Implement i18n rules from #377
@abierbaum
Copy link

@mgechev Thanks for adding this!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants