October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

Manage Marked Text with Custom IDs in Angular

Add custom IDs to Angular translation-marked text with @@ metadata in templates or $localize strings. Learn the syntax, context fields, and trade-offs versus generated IDs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To assign Angular translation-marked text a custom ID, add @@ followed by the ID in the message’s i18n metadata. In a template, use an i18n attribute; in component code, use a $localize tagged string. These IDs identify text for translation—they do not highlight text in the rendered interface.

Set a custom ID in a component template

Place the ID in the i18n attribute, prefixed by @@:

As an Amazon Associate I earn from qualifying purchases.

<h1 i18n="@@introductionHeader">Hello i18n!</h1>

Angular’s translation extractor creates a translation unit for this marked text. The ID, introductionHeader, is the custom identifier for that unit. See Angular’s custom-ID guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set a custom ID in component code

For a message in component code, use the same metadata syntax in a $localize tagged string:

variableText = $localize`:@@introductionHeader:Hello i18n!`;

Angular extracts $localize-tagged messages as translation units too. The template and code examples use the same ID here for illustration; in an application, each distinct message should have its own unique custom ID.

Add translator context to the metadata

Metadata can include a meaning and a description before the custom ID. The format is {meaning}|{description}@@{custom_id}:

<h1 i18n="site header|An introduction header for this sample@@introductionHeader">
  Hello i18n!
</h1>

Meaning identifies the message’s intent in context; description supplies additional context for translators. If one kind of context is unnecessary, the metadata can omit it while retaining the ID. Angular documents this syntax for marked messages and translatable element attributes; see Prepare component for translation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose between generated and custom IDs

Angular normally generates message IDs. The choice is mainly about your translation workflow and how you want source changes to be managed:

Approach When it fits What happens when source text changes
Generated ID Use it by default when your translation system does not require a particular ID format and a stable, descriptive identifier is not needed. Angular’s generated ID normally changes when the translatable source text changes.
Custom ID Use it when a translation system requires a particular ID format, or when a stable ID that conveys library, component, or application-area information is useful. The ID remains the same. Review the corresponding translation when the source changes, since the identifier itself will not signal that the text has changed.

These behaviors are described in Angular’s custom-ID documentation. For the broader localization context, see Angular v18’s internationalization overview.

Keep custom IDs unique

Give each distinct message a unique custom ID. If two different messages reuse one, Angular’s extractor extracts only the first message for that ID, and Angular can use that message’s translation for both elements. A consistent naming convention can help teams avoid collisions; for example, IDs can convey the relevant component or application area when that information is useful.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Remember what “marked text” means

In Angular’s internationalization guides, marked text is source text identified for translation. It is separate from changing an element’s appearance or behavior through an attribute directive. Angular’s attribute-directive guide covers that separate UI concept.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.