How to Protect Brand Names, SKUs, and Code Blocks During HTML Translation
Use translate="no" to mark brand names, SKUs, and literal code that must survive HTML translation unchanged. It’s the standard HTML signal for protecting an element’s text and translatable attributes, but your translation service, CMS, or email editor may strip or ignore it. Test the final export rather than relying on the markup alone.
Protect the smallest unit that must stay exact, and leave the surrounding sentence available for translation. When you control extraction, keep protected values out of the translator’s input altogether. Then compare the source and localized output to catch changes that a visual review can miss, such as a different hyphen in a SKU or a space added to a command.
Mark the Invariant Text, Not the Whole Sentence
A product card usually contains three kinds of content: a canonical brand name, a machine identifier, and copy that should read naturally in the target language. Applying translate="no" to the whole card merges those decisions into one.
<!-- Broken: the entire card is excluded from translation. -->
<article translate="no">
<h2>Northstar Studio desk lamp</h2>
<p>Order using SKU NS-LAMP-042.</p>
<a href="/products/ns-lamp-042">View product details</a>
</article>
A tool that honors the attribute can leave the heading’s product description, the ordering instructions, and the link text in the source language. Check ancestor elements when an unexpectedly large section comes back untranslated: the translation state is inherited.
<!-- Fixed: only the canonical values are excluded. -->
<article>
<h2><span translate="no">Northstar Studio</span> desk lamp</h2>
<p>Order using SKU <code translate="no">NS-LAMP-042</code>.</p>
<a href="/products/ns-lamp-042">View product details</a>
</article>
The descriptor, ordering instructions, and link text can now be translated. Keep punctuation that belongs to the sentence outside the protected element so the locale can use its own punctuation and spacing. Also check that your extractor gives translators the full sentence with an inline tag or placeholder, rather than submitting each text node separately and freezing the source word order.
Never translate or normalize a SKU that doubles as a lookup key.
NS-LAMP-042contains ordinary hyphens; a visually similar dash can still break a lookup.
Choose What to Translate by Content Type
| Content | Treatment | What to verify |
|---|---|---|
| Canonical brand | Wrap the official name in <span translate="no">. | Preserve casing, diacritics, and any trademark symbol that belongs to the approved spelling. |
| Approved local brand spelling | Select the value from your locale catalog, then render it with translate="no". | Use the approved spelling for that market; don’t let the translation engine invent one. |
| Visible SKU or identifier | Use <code translate="no">NS-LAMP-042</code> when it’s a literal identifier. | Compare decoded text exactly, including leading zeros, case, and hyphens. |
| Command or configuration example | Use <pre translate="no"><code> for a fully literal block. | Compare whitespace as well as characters; check that copying the rendered example works. |
| Accessible label or image description | Keep localizable text such as alt="Northstar Studio desk lamp" on an element that can be translated. | Translate the description without changing the canonical brand. You can’t wrap just part of an attribute value in a <span>. |
| Machine-readable data | Keep values such as data-sku="NS-LAMP-042" out of the extraction allowlist. | Compare attributes independently of visible text. Handle locale-specific href values through routing, not prose translation. |
Use translate="no" for protection, not lang. The lang attribute describes the language of content and can affect pronunciation and other language-dependent behavior; it doesn’t tell a localization service to preserve a string. Likewise, <code> describes the kind of text it contains, not whether it should be translated.
Protect Code Without Freezing Its Explanation
Keep executable examples separate from localized instructions. For shell commands, flags and arguments may be significant; for Python and YAML, indentation can be significant too. Don’t attach the protection to the surrounding figure if its caption needs localization.
<figure>
<pre translate="no"><code>mkdir -p "release notes"
printf '%s\n' 'NS-LAMP-042' > "release notes/sku.txt"
cat "release notes/sku.txt"</code></pre>
<figcaption>Write the SKU to a file, then print it to verify the result.</figcaption>
</figure>
The HTML parser decodes > to the shell redirection character >, while the caption remains available for translation. If a serializer uses a different entity spelling but produces the same decoded text, the command hasn’t changed. If a formatter inserts indentation between the tags and the command, however, that indentation can become part of the copied block; compare the parsed text, not just the source markup.
Never let a prose translator rewrite runnable code. If a comment or sample output needs localization, put the explanation next to the block or maintain a separate, tested localized example.
Use Placeholders When the Translator Only Accepts Text
If your workflow extracts text before translation, HTML attributes won’t reach the translator. Replace protected values with named placeholders in the translation unit, and keep the originals in application data. Use the translation system’s native placeholder support where available; otherwise, treat your placeholder convention as a format that needs explicit validation.
{
"id": "order.lookup",
"source": "To order from {brand}, enter SKU {sku}.",
"target": "Introduce el SKU {sku} para hacer un pedido a {brand}.",
"values": {
"brand": "Northstar Studio",
"sku": "NS-LAMP-042"
}
}
The Spanish sentence moves both placeholders without changing the values they represent. Validate the returned placeholders by name and count, not by position; for this message, reject a missing, renamed, duplicated, or unknown placeholder before rendering. Interpolate values as text through an auto-escaping template or DOM text nodes, not by concatenating the translated sentence into raw HTML.
The same approach works for attributes such as alt and aria-label: translate the description with a placeholder, restore the brand, and set the completed attribute through a template that escapes attribute values or through setAttribute(). If the translation makes the brand grammatically awkward, rewrite the surrounding phrase rather than modifying the canonical name.
Compare the Final Localized Export
Test the HTML after the last CMS, translation, or email-editor step. For a template you control, add stable data-protect-id values to the protected fields you want to compare. Put those IDs on leaf elements: a comparison of a container’s full text would also include legitimate changes in localized descendants.
<p>Order using SKU
<code translate="no" data-protect-id="product-sku">NS-LAMP-042</code>.
</p>
<pre translate="no"><code data-protect-id="print-sku">printf '%s\n' 'NS-LAMP-042'
</code></pre>
Use the same IDs in the source and localized export, even if the elements move within a sentence. The newline before </code> in this example is part of the protected text. If an editor strips custom attributes, validate before that step and identify the same fields in a final-output test using selectors the editor preserves.
function readProtectedText(html) {
const doc = new DOMParser().parseFromString(html, "text/html");
const entries = new Map();
for (const node of doc.querySelectorAll("[data-protect-id]")) {
const id = node.getAttribute("data-protect-id");
if (!id || entries.has(id)) {
throw new Error(`Missing or duplicate protection ID: ${id}`);
}
entries.set(id, node.textContent);
}
if (entries.size === 0) throw new Error("No protection IDs found");
return entries;
}
function assertProtectedText(sourceHtml, localizedHtml) {
const source = readProtectedText(sourceHtml);
const localized = readProtectedText(localizedHtml);
for (const [id, expected] of source) {
if (!localized.has(id)) throw new Error(`Missing in export: ${id}`);
if (localized.get(id) !== expected) {
throw new Error(`Protected text changed: ${id}`);
}
}
for (const id of localized.keys()) {
if (!source.has(id)) throw new Error(`Unexpected protection ID: ${id}`);
}
}
In a browser-based QA test, pass the two export strings to assertProtectedText(sourceHtml, localizedHtml); the comparison tolerates HTML entity spelling differences but catches text changes after parsing. Don’t add .trim() or Unicode normalization if exact decoded text is the contract. This check doesn’t compare attributes or verify raw file bytes, so add separate assertions for machine-readable fields and test copy-and-paste in the rendered page or received email.
Use HTML Translate to preview a small fixture with a protected brand, SKU, and command before checking the exported HTML.
Common Mistakes and Troubleshooting
- The whole product card stays in the source language. Look for an ancestor with
translate="no". Move it down to the invariant strings, or explicitly usetranslate="yes"on a descendant that should be translated and verify that the tool honors the override. - The translation tool changes the brand anyway. Compare the HTML entering and leaving the service. If
translate="no"is stripped or ignored, exclude the value during extraction and restore it from a placeholder such as{brand}. - The SKU looks right but fails a search. Compare the decoded value to
NS-LAMP-042exactly. Watch for lookalike dashes, nonbreaking spaces, removed zeros, or casing changes. - A code sample displays as markup or loses characters. Encode literal markup characters in the HTML source, using
<for<and&for&. Confirm that rendered text matches what a reader should copy. - The brand survived, but the translated sentence sounds wrong. Submit the whole sentence with a movable
{brand}placeholder or inline tag instead of translating the text on either side separately. - Visible text is correct but the accessible label isn’t. Check
altandaria-labelseparately. Extract localizable prose from those attributes and restore any protected value before writing the final label.
HTML File Translation Questions
Is class="notranslate" the same as translate="no"?
No. translate="no" has defined HTML semantics. class="notranslate" is a class name whose effect depends on a specific tool. Add it only if a tool you use documents support for it, and test the exported result.
Does translate="no" hide text from search engines or screen readers?
No. The attribute describes translation behavior; it doesn’t hide content, remove it from the accessibility tree, or act as a search indexing directive.
Should you protect every product name?
Protect canonical names and identifiers. Translate generic descriptions, option labels, and feature names unless your brand glossary treats them as fixed. If a market has an approved name, select that value first and protect it afterward.
Can a protected name move within a translated sentence?
Yes, if your workflow preserves the full sentence and supports movable inline tags or placeholders such as {brand}. Protecting a name means preserving its value, not pinning it to its original position.
How do you preserve mixed-direction SKUs in right-to-left content?
Use bidirectional isolation when a left-to-right identifier interacts badly with surrounding punctuation, for example <bdi dir="ltr" translate="no">NS-LAMP-042</bdi>. Direction and translation are independent; preview the result in the target browser or email client.
What if an email editor removes translate="no"?
Keep the literal values out of translation, then restore them during template rendering. Check the actual test-send output as well as the editor preview, especially if another processing step rewrites the rendered HTML.