Reputation: 2290
Due to i18n tutorial in https://angular.io/guide/i18n, every translated message should have a unique id.
The question is, if anyone faced some convention of id strings in a big application? What should contain such id pattern, to have a low risk of id repetition and get easy maintenance of messages translations, when there is a lot of components, subcomponents and so on?
Upvotes: 1
Views: 1109
Reputation: 1834
At this moment I am using the following convention
@@<modulename|libraryname>.<componentname>.<keyname[-<extension>]> - all lower case.
I avoid the "Component" suffix of a Component name. This helps me namespace, identify, ensure uniqueness for keys throughout an application and even when used in an external application when module/components are deployed as a library.
Upvotes: 2
Reputation: 1037
I use meaning values as context. So instead of using
<p i18n>This is a sample</p>
or
<p i18n="@@sample">This is a sample</p>
I use the meaning value. Like this
<p i18n="sample|">This is a sample</p>
Remember to add the pipe character! Otherwise extract tool will take the value as description. The extract tool will generate the id but my localization tool ignores it. Instead it uses combination of meaning and location attributes in the resource file to get a unique ID. This makes writing code much easier because we do not have to have unique ID among all templates (e.g. hundreds of files) but only among one single file.
If for some reason the meaning is missing in a template my localization tool writes a warning and uses the generated id as a context instead of meaning+location. Developers will quickly see where meaning is missing and can add them.
It is easy to make sure that meaning in a single file (template) are unique but it is impossible to have the unique globally when you have several developers and hundreds of templates.
Upvotes: 0