A product writer fixes a typo in a checkout button, and the next build ships that button in English to every other language. A developer moves a component into a new folder, renames its keys to match the path, and translators get a batch of "new" strings they already translated last quarter. Neither change touched translation quality; the key scheme caused both.
A translation key naming convention decides what happens to existing translations when copy, code, or context changes. This guide compares the three key styles by that behavior, shows the separator and platform traps that the usual naming advice skips, and gives a rename procedure that keeps translated work attached. It is written for engineers and localization leads working across iOS, Android, and JavaScript catalogs.
The short answer
- Use semantic keys named after the product feature and the job of the string, such as
checkout.payment.submit, when copy will be edited after translation. The key stays put while the English changes. - Use source-text keys or generated IDs only when you want every English edit to send the string back for translation, and accept that tradeoff explicitly.
- Give a string its own key whenever its meaning differs, even if the English is identical.
- Keep keys static in code so extractors can see them.
- Treat any key rename as a migration with an old-to-new map, not as a find-and-replace.
Three key styles and what each does to a copy edit
Compare the styles by what happens when someone edits the English text after translations exist.
| Key style | Example | What an English edit does | Best fit |
|---|---|---|---|
| Semantic key | checkout.payment.submit |
Key unchanged, translations stay attached and need a freshness check | Products with ongoing copy iteration |
| Source text as key | "Pay now" |
Key changes, old translations orphaned | Small apps, gettext projects with fuzzy matching |
| Generated ID | MbT6FE |
ID is recomputed from the message, so it changes too | Teams that want zero naming work and strong tooling |
A Stack Overflow question on key values in translation files (score 36 and more than 9,000 views) describes a team split between full English sentences as keys and descriptive keys like ENTER_EMAIL. The author notes that English keys need updates in every file when copy changes, while descriptive keys lose context and collide more easily. A similar question about .resx key naming conventions has more than 18,000 views. These are practitioner reports from PHP and .NET projects; the i18next thread later in this guide shows the same debate in JavaScript.
Generated IDs look stable, yet they change whenever the message changes. Lingui's guide to explicit and generated IDs explains that generated IDs are created from the source message and context, while explicit IDs are loosely coupled: if the message changes, the ID remains the same. FormatJS message extraction shows the same idea with an --id-interpolation-pattern of [sha512:contenthash:base64:6]. A content hash moves when the content moves, so an edited default message gets a new ID. That is a feature if you want edits to trigger retranslation, and a cost if your writers polish copy weekly.
Semantic keys keep translations attached, which creates a different risk: the French text may now describe old English. Our guide on controlling source string changes covers that half of the problem with source fingerprints. Use both: stable keys keep translations attached, and fingerprints tell you when an attached translation has fallen behind the English.
Name keys by feature and meaning, not by file
Once you choose semantic keys, the structure inside the key matters. The common advice is to namespace by feature and nest a few levels deep. Locize's key naming guide recommends feature or domain namespaces such as checkout with two to three levels of nesting, and the Modern.js i18n best practices recommend module prefixes like auth.login.title and warn against using complete source text as keys.
Whether a key survives a refactor depends on which nouns you put in it. The GNU gettext manual on contexts gives the clearest rule, written about msgctxt but equally true of keys: the context string should be canonical and never change, because every change forces the translator to review the translation. It specifically warns against using a file or class name, since renaming files and classes is routine, and against using a full English sentence, since grammar fixes are routine too.
Apply that to keys:
- Good:
checkout.payment.submit,profile.avatar.remove_confirm. Product concepts outlive file layouts. - Fragile:
CheckoutScreenV2.button1,components.PaymentForm.cta. The next folder reorganization rewrites them. - Fragile:
checkout.pay_now_and_confirm. The key repeats today's copy, so the next copy change makes the key a lie or forces a rename.
This is a recommendation drawn from the gettext guidance; no library enforces it. It keeps refactors out of the translation queue at almost no cost.
Split keys when meaning differs
Shared keys look efficient. Lokalise's key naming practices suggest a global namespace for words like Save, Next, and Cancel, while also advising teams to remove a link and create a separate key when a reused translation does not fit the context. "Save" on a document toolbar and "Save" on a pricing badge ("Save 20%") are different words in many languages, so the separate-key exception comes up as soon as a shared word spreads across screens.
Apple's documentation shows the platform version of the rule. The reference for String(localized:defaultValue:table:bundle:locale:comment:) uses "Call" as its example: in English it can be a noun or a verb, so the catalog holds CALL_VERB and CALL_NOUN, which French translates as "Appeler" and "Appel". Lingui reaches the same answer with context: its guide uses "right" as in "you are right" versus "turn right" and extracts them under different IDs. The i18nAgent article on giving translators context for ambiguous strings covers the comments and screenshots that should travel with those keys.
Share a key only when the string has the same meaning, the same grammatical role, and the same length budget everywhere it appears. If any of the three differs, give it its own key.
Separators and the natural-language key trap
Natural-language keys collide with i18next's default dot and colon separators, so turn keySeparator and nsSeparator off before the first sentence-shaped key ships.
The i18next configuration options document keySeparator as . and nsSeparator as :, and note that keySeparator can be set to false for flat keys. With the defaults, a key such as Error: file not found. is read as namespace Error and a nested path ending in an empty segment. One Stack Overflow report about colons in i18next strings describes a CMS whose developers add keys containing colons inside HTML, which i18next then treats as namespace and key pairs. Because that CMS relies on its own namespace, the team could not simply turn namespacing off.
The i18next fallback documentation shows the supported setup: phrases as keys with nsSeparator: false and keySeparator: false, where a missing translation falls back to the key itself.
// Natural-language keys: decide this on day one
i18next.init({
nsSeparator: false, // "Note: saved." stays one key
keySeparator: false, // "Version 2.1 ready" is not a nested path
ns: ["app", "checkout"],
defaultNS: "app",
});
t("Note: your changes were saved.");
t("Pay now", { ns: "checkout" }); // namespace via option, not "checkout:Pay now"
Most key-naming guides discuss nesting with dots and do not mention what the dot and colon do to sentence-shaped keys. If you already have nested semantic keys in the same project, you cannot turn keySeparator off globally without flattening them, so choose one style per namespace and keep a lint rule that rejects keys containing : or . in natural-language namespaces.
Keep keys static so tools can see them
Extraction and cleanup tools read code without running it. The i18next-parser README states that it cannot interpolate values in expressions such as t(key), t('key' + id), or template literals, and suggests listing the possible static keys in comments as a workaround. If keys are assembled at runtime, extraction misses them, translators never see them, and unused-key reports flag them as dead.
When a value maps to a message, write the mapping out:
const STATUS_KEYS = {
pending: "orders.status.pending",
shipped: "orders.status.shipped",
refunded: "orders.status.refunded",
} as const;
t(STATUS_KEYS[order.status]);
The map costs a few lines and makes every key a literal that extractors, type generators, and reviewers can find. Retiring unused keys is the cleanup side of the same problem; here the point is that naming and code shape decide whether those tools can work at all.
Platform rules: Apple, Android, and gettext
On Apple platforms a plain String(localized:) call or SwiftUI Text literal uses its English text as the key, so give an explicit key and default value to any string whose English is ambiguous or likely to be rewritten.
The Apple reference above states the split directly: use the String(localized:defaultValue:...) initializer when you want an explicit key, and the default-localization variant when the development-language text should be the key. Apple's guide to localizing and varying text with a string catalog describes Xcode populating the catalog on build and mentions localizable symbols as an alternative to string literals. For a team, that means the default behavior is source-text keys. Any writer edit to a literal becomes a new catalog entry, and the old translated entry no longer matches code.
// Source text is the key: a copy edit creates a new entry
Text("Pay now")
// Explicit key: copy can change, the key and translations stay attached
let payLabel = String(
localized: "checkout.payment.submit",
defaultValue: "Pay now",
comment: "Primary button on the payment step"
)
Mixing the two is fine. Use literals for short, stable strings and explicit keys for anything marketing will iterate on.
On Android, the string resources guide states that the <string> element's name is used as the resource ID, referenced as R.string.string_name in code. Every key is therefore a code symbol. Renaming one is a compile-time change across the module, which is safer than JavaScript string keys, but translations in values-fr/strings.xml and your TMS still need the same rename. Use snake_case names that follow the feature-first rule, such as checkout_payment_submit.
For gettext projects, the msgid is the English text and msgctxt is the disambiguator. The gettext rule above applies: pick a canonical context like menu|file and never derive it from a file or class name.
Rename keys without losing translations
A key rename is a translation migration, not a refactor: extraction tools file the old key away and create an empty new one, so rename through an explicit old-to-new map applied to code, every locale file, and the TMS together.
The i18next-parser README describes the mechanism. It backs up keys your code no longer uses into a namespace_old.json catalog and restores a key from that file only when the same key is empty. A renamed key has a different name, so nothing is restored: the new key ships empty in every locale, and the translated text sits in the backup file. Translation management systems vary, but Lokalise's governance advice to restrict who can rename or delete keys points at the same risk.
A safe rename looks like this:
1. Write renames.json: { "cart.cta": "checkout.payment.submit", ... }
2. In one change set:
a. rewrite call sites in code
b. move the value in every locale file from old key to new key
c. apply the same rename in the TMS (rename, not delete and create)
3. Run extraction; it must report zero new empty keys and zero
keys moved to the old/backup catalog for the renamed set
4. Keep a read-only alias from old to new for one release if
remote catalogs or older app versions still request the old key
5. Delete renames.json entries after the alias period ends
Step 3 is the check that catches a half-done rename. If extraction shows any renamed key as new and empty, stop and fix the locale files before translators are notified.
Verify the scheme
Add these checks to CI so the convention holds after the person who wrote it moves on:
- Every key matches the namespace pattern for its style, for example
^[a-z]+(\.[a-z_]+){1,3}$for semantic namespaces. - Natural-language namespaces have no key containing
:or., or run with both separators off. - No call site builds a key from a variable unless it reads from a reviewed static map.
- A rename map, when present, produces zero empty new keys in any locale after extraction.
- Each key with an ambiguous English value (a short verb or noun) carries a translator comment.
Run the same checks on iOS and Android catalogs by exporting them to a common list of keys and values. The rules are about names, so they port across file formats.
Common mistakes
- Choosing generated IDs to avoid naming, then letting writers edit copy freely. Every edit becomes a new ID and a new translation job.
- Encoding the screen or component in the key. The next redesign renames every key on that screen.
- Reusing
common.savefor a toolbar action and a discount badge. - Turning
keySeparatoroff for one natural-language namespace and breaking nested keys elsewhere. - Renaming keys with a global find-and-replace in code only, leaving locale files and the TMS on the old names.
What to do next
Pick the namespace that changes most often, usually checkout or onboarding, and list its keys. Mark each one as semantic, source text, or generated, and flag every key that contains a file, class, or screen name. Convert those to feature-first names with a rename map and run the extraction check from step 3 before anything reaches translators. That single namespace will show whether your translation key naming convention holds up, and it gives you the rename script for the rest of the catalog.
