Skip to content

Backoffice Localization (v18.1): Document type-safe keys for plugin authors#8073

Draft
iOvergaard wants to merge 1 commit into
mainfrom
cms/v18/typesafe-localization-keys-docs
Draft

Backoffice Localization (v18.1): Document type-safe keys for plugin authors#8073
iOvergaard wants to merge 1 commit into
mainfrom
cms/v18/typesafe-localization-keys-docs

Conversation

@iOvergaard

Copy link
Copy Markdown
Contributor

📋 Description

Adds a new Type-safe localization keys section to 18/umbraco-cms/extend-your-project/backoffice-extensions/foundation/localization.md, documenting the compile-time validation that ships in Umbraco 18.1 via umbraco/Umbraco-CMS#22887.

The new section covers:

  • For consumers of the built-in dictionarylocalize.term(), termOrDefault(), and the <umb-localize key=\"…\"> element now autocomplete every canonical key and check function-entry arguments at compile time.
  • For plugin authors — how to extend the type system with the plugin's own keys via plain global interface merging (declare global { interface UmbKnownLocalizationSet { … } }), same pattern as UmbExtensionManifestMap.
  • Escape hatch — dynamic keys composed at runtime (e.g. ```login_greeting${day}```) still type-check without casts, and plugins that skip the type declaration still work — they just lose autocomplete on their own keys.

Lives between Using the Localizations and Using arguments in the existing article — the natural flow goes: register → use → type-safety story → arg/placeholder details.

v17 docs are intentionally left unchanged. The feature is v18.1+.

📎 Related Issues (if applicable)

Documents umbraco/Umbraco-CMS#22887.

✅ Contributor Checklist

I've followed the Umbraco Documentation Style Guide and can confirm that:

  • Code blocks are correctly formatted.
  • Sentences are short and clear (preferably under 25 words).
  • Passive voice and first-person language ("we", "I") are avoided.
  • Relevant pages are linked.
  • All links work and point to the correct resources.
  • Screenshots or diagrams are included if useful.
  • Any code examples or instructions have been tested.
  • Typos, broken links, and broken images are fixed.

Product & Version (if relevant)

Umbraco CMS v18.1.

Deadline (if relevant)

Ideally lands alongside the v18.1 release so the docs and the feature ship together.

Adds a "Type-safe localization keys" section to the Backoffice
Localization article covering the new compile-time validation in
v18.1+:

- `localize.term()`, `termOrDefault()`, and `<umb-localize key="…">`
  are typed against the built-in English dictionary; editors
  autocomplete every key, function-valued entries forward their
  parameter list for compile-time arg checking.
- Plugin authors can extend the typing with their own keys via plain
  `declare global { interface UmbKnownLocalizationSet { … } }` — same
  pattern as `UmbExtensionManifestMap`. The type declaration is opt-in;
  plugins that skip it still work, they just lose autocomplete and
  arg-type checking on their own keys.

Lands the developer-facing half of umbraco/Umbraco-CMS#22887.
Copilot AI review requested due to automatic review settings May 19, 2026 18:46
@github-actions

Copy link
Copy Markdown

Thanks for opening this PR! 🎉

Quick question: Does this PR include any AI-generated content?

AI tools are absolutely welcome here! We only ask that you follow our AI contribution guidelines to help keep the documentation consistent and trustworthy.

Drop a quick comment to let us know!

@iOvergaard iOvergaard marked this pull request as draft May 19, 2026 18:47
Available from Umbraco 18.1.
{% endhint %}

The `localize.term()` and `localize.termOrDefault()` methods, and the `key` attribute on `<umb-localize>`, are typed against the canonical English dictionary that ships with the backoffice. Editors that support TypeScript (VS Code, WebStorm, Rider) autocomplete every known key as you type, and function-valued entries forward their parameter list so calls are checked at compile time:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [vale] reported by reviewdog 🐶
[UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words). For content inside note or warning blocks, add blank lines around the content.

Available from Umbraco 18.1.
{% endhint %}

The `localize.term()` and `localize.termOrDefault()` methods, and the `key` attribute on `<umb-localize>`, are typed against the canonical English dictionary that ships with the backoffice. Editors that support TypeScript (VS Code, WebStorm, Rider) autocomplete every known key as you type, and function-valued entries forward their parameter list so calls are checked at compile time:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [vale] reported by reviewdog 🐶
[UmbracoDocs.Brands] Use 'Visual Studio Code' instead of 'VS Code' for brand consistency.


### Adding plugin-specific keys

Once you have [registered your localization extension](#registering-localization), you can teach the type system about your own keys by extending the global `UmbKnownLocalizationSet` interface from anywhere in your code (same pattern as `UmbExtensionManifestMap`):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [vale] reported by reviewdog 🐶
[UmbracoDocs.SentenceLength] Write shorter sentences (less than 25 words). For content inside note or warning blocks, add blank lines around the content.

this.localize.term('mypkg_greeting', 'Alice'); // 'Alice' checked against (name: string) => string
```

The type declaration is opt-in — plugins that skip it still work, because the `term()` signature accepts any string. You just lose autocomplete and argument-type checking on the plugin's own keys.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [vale] reported by reviewdog 🐶
[UmbracoDocs.Editorializing] Consider removing 'just' as it can be considered opinionated.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds documentation for Umbraco CMS v18.1’s type-safe localization key support, aimed at both consumers of the built-in dictionary and plugin authors extending localization key types.

Changes:

  • Introduces a new “Type-safe localization keys” section with examples of compile-time validation and IDE autocomplete.
  • Documents an escape hatch for dynamically composed localization keys.
  • Explains how plugin authors can add their own key typings via global interface merging (UmbKnownLocalizationSet).
Comments suppressed due to low confidence (1)

18/umbraco-cms/extend-your-project/backoffice-extensions/foundation/localization.md:114

  • This sentence exceeds the documentation style guide’s 25-word guideline and is doing multiple jobs (prerequisite + how to extend types + analogy). Splitting it into shorter sentences will improve scanability (e.g., first sentence about prerequisite registration, second about augmenting UmbKnownLocalizationSet, third about the UmbExtensionManifestMap pattern).
Once you have [registered your localization extension](#registering-localization), you can teach the type system about your own keys by extending the global `UmbKnownLocalizationSet` interface from anywhere in your code (same pattern as `UmbExtensionManifestMap`):

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Available from Umbraco 18.1.
{% endhint %}

The `localize.term()` and `localize.termOrDefault()` methods, and the `key` attribute on `<umb-localize>`, are typed against the canonical English dictionary that ships with the backoffice. Editors that support TypeScript (VS Code, WebStorm, Rider) autocomplete every known key as you type, and function-valued entries forward their parameter list so calls are checked at compile time:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants