Performance: Marking text for translation
This affects initial page load speed and rendering because translation markers can increase template size and processing time.
Jump into concepts and practice - no test required
<p i18n>Welcome to our site, {{ userName }}! Click here to start. Contact us for support.</p><p i18n>Welcome to our site, {{ userName }}!</p>
<p i18n>Click here to start.</p>
<p i18n>Contact us for support.</p>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Many small i18n markers | High (many nodes) | Multiple reflows | High paint cost | [X] Bad |
| Few combined i18n markers | Low (fewer nodes) | Single reflow | Lower paint cost | [OK] Good |
i18n attribute in Angular templates?i18n in Angulari18n attribute is used to mark text that should be translated for different languages.i18n attribute can include a description or meaning using the syntax i18n="@@desc" to help translators.Welcome to our site!
correctly usesi18n="@@desc" inside the paragraph tag. Options B, C, and D misuse the attribute or place description incorrectly.Welcome to our site!
[OK]<h1 i18n="@@titleDesc">Hello, user!</h1>What will Angular do with this text during the build process?
i18n for translation and uses the description (after @@) to help translators identify the text.<button i18n="Submit button">Submit</button>
i18n="@@Submit button".button. Text does not require curly braces for static content. The attribute i18n-desc is not valid.i18n="@@description" to add unique descriptions for each translatable text.This is the intro paragraph.
correctly usesi18n="@@headerDesc" and i18n="@@introDesc". This is the intro paragraph.
uses invalidi18n-desc. This is the intro paragraph.
misses @@ prefix.This is the intro paragraph.
uses plain text instead of description keys.