重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
umbraco-localization by umbraco/umbraco-cms-backoffice-skills
npx skills add https://github.com/umbraco/umbraco-cms-backoffice-skills --skill umbraco-localization本地化功能通过由扩展注册表管理的本地化文件实现用户界面的翻译,其中英语(ISO 代码:'en')作为备用语言。本地化控制器(在 Umbraco 元素中通过 this.localize 自动可用)提供使用键来访问已翻译字符串的功能。可以通过扩展注册表添加自定义翻译,并在清单中使用 # 前缀进行引用。
在实施前请务必获取最新文档:
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
import { html, customElement } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
@customElement('my-element')
export class MyElement extends UmbLitElement {
render() {
return html`
<uui-button .label=${this.localize.term('general_close')}>
${this.localize.term('general_close')}
</uui-button>
<p>${this.localize.term('general_welcome')}</p>
`;
}
}
import { html, customElement } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
@customElement('my-element')
export class MyElement extends UmbLitElement {
render() {
return html`
<p>渲染 "Welcome": ${this.localize.term('general_welcome')}</p>
<p>渲染 "This is a fallback": ${this.localize.termOrDefault('test_unavailable', 'This is a fallback')}</p>
`;
}
}
render() {
return html`
<button>
<umb-localize key="dialog_myKey">默认文本</umb-localize>
</button>
`;
}
import { UmbLocalizationController } from '@umbraco-cms/backoffice/localization-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
export class MyController extends UmbControllerBase {
#localize = new UmbLocalizationController(this);
render() {
return html`
<uui-button .label=${this.#localize.term('general_close')}>
</uui-button>
`;
}
}
// en.js
export default {
myExtension: {
welcomeMessage: 'Welcome to my extension!',
itemCount: 'You have {0} items',
goodbye: 'Goodbye, {0}!',
},
};
// manifest.ts
export const manifests = [
{
type: 'localization',
alias: 'My.Localization.En',
name: 'English Localization',
meta: {
culture: 'en',
},
js: () => import('./localization/en.js'),
},
];
render() {
return html`
<h1>${this.localize.term('myExtension_welcomeMessage')}</h1>
<p>${this.localize.term('myExtension_itemCount', 5)}</p>
`;
}
// 带函数的本地化文件
export default {
section: {
numberOfItems: (count) => {
if (count === 0) return 'Showing nothing';
if (count === 1) return 'Showing only one item';
return `Showing ${count} items`;
},
},
};
// 使用
render() {
return html`
<umb-localize
key="section_numberOfItems"
.args=${[this._itemCount]}
></umb-localize>
`;
}
{
"type": "dashboard",
"alias": "My.Dashboard",
"name": "My Dashboard",
"meta": {
"label": "#welcomeDashboard_label",
"pathname": "welcome"
}
}
// 通用
this.localize.term('general_close')
this.localize.term('general_cancel')
this.localize.term('general_save')
this.localize.term('general_delete')
this.localize.term('general_welcome')
// 操作
this.localize.term('actions_create')
this.localize.term('actions_edit')
this.localize.term('actions_remove')
// 对话框
this.localize.term('dialog_confirm')
this.localize.term('dialog_cancel')
<!-- 显示键别名而非值,用于故障排除 -->
<umb-localize key="myExtension_welcomeMessage" debug="true"></umb-localize>
// en.js
export default {
greeting: 'Hello',
};
// da.js (丹麦语)
export default {
greeting: 'Hej',
};
// 注册两者
export const manifests = [
{
type: 'localization',
alias: 'My.Localization.En',
meta: { culture: 'en' },
js: () => import('./localization/en.js'),
},
{
type: 'localization',
alias: 'My.Localization.Da',
meta: { culture: 'da' },
js: () => import('./localization/da.js'),
},
];
本地化控制器 : 在 Umbraco 元素中通过 this.localize 自动可用
翻译键 : 使用下划线表示法(例如,general_close、myExtension_welcomeMessage)
备用语言 : 当翻译缺失时,英语(en)是默认的备用语言 - 所有扩展至少应包含一个 'en' 本地化清单
默认文本 : 如果不确定本地化键是否存在,或者为了更好的可读性,可以向 <umb-localize key="section_key">默认文本</umb-localize> 添加默认文本,或作为 termOrDefault() 的第二个参数
参数 : 使用 .args 属性或 term() 的第二个参数传递动态值
清单本地化 : 在值前加上 # 以引用翻译键
调试模式 : 使用 debug="true" 显示键别名以进行故障排除
文件结构 :
就是这样!请务必获取最新文档,保持示例简洁,生成完整可用的代码。
每周安装次数
72
代码仓库
GitHub 星标数
14
首次出现
2026年2月4日
安全审计
安装于
github-copilot52
cursor25
opencode24
codex23
gemini-cli22
amp21
Localization enables UI translation through localization files managed by the Extension Registry, with English (iso code: 'en') as the fallback language. The Localization Controller (automatically available in Umbraco Elements via this.localize) provides access to translated strings using keys. Custom translations can be added via the Extension Registry and referenced in manifests using the # prefix.
Always fetch the latest docs before implementing:
import { html, customElement } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
@customElement('my-element')
export class MyElement extends UmbLitElement {
render() {
return html`
<uui-button .label=${this.localize.term('general_close')}>
${this.localize.term('general_close')}
</uui-button>
<p>${this.localize.term('general_welcome')}</p>
`;
}
}
import { html, customElement } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
@customElement('my-element')
export class MyElement extends UmbLitElement {
render() {
return html`
<p>Renders "Welcome": ${this.localize.term('general_welcome')}</p>
<p>Renders "This is a fallback": ${this.localize.termOrDefault('test_unavailable', 'This is a fallback')}</p>
`;
}
}
render() {
return html`
<button>
<umb-localize key="dialog_myKey">Default Text</umb-localize>
</button>
`;
}
import { UmbLocalizationController } from '@umbraco-cms/backoffice/localization-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
export class MyController extends UmbControllerBase {
#localize = new UmbLocalizationController(this);
render() {
return html`
<uui-button .label=${this.#localize.term('general_close')}>
</uui-button>
`;
}
}
// en.js
export default {
myExtension: {
welcomeMessage: 'Welcome to my extension!',
itemCount: 'You have {0} items',
goodbye: 'Goodbye, {0}!',
},
};
// manifest.ts
export const manifests = [
{
type: 'localization',
alias: 'My.Localization.En',
name: 'English Localization',
meta: {
culture: 'en',
},
js: () => import('./localization/en.js'),
},
];
render() {
return html`
<h1>${this.localize.term('myExtension_welcomeMessage')}</h1>
<p>${this.localize.term('myExtension_itemCount', 5)}</p>
`;
}
// Localization file with function
export default {
section: {
numberOfItems: (count) => {
if (count === 0) return 'Showing nothing';
if (count === 1) return 'Showing only one item';
return `Showing ${count} items`;
},
},
};
// Usage
render() {
return html`
<umb-localize
key="section_numberOfItems"
.args=${[this._itemCount]}
></umb-localize>
`;
}
{
"type": "dashboard",
"alias": "My.Dashboard",
"name": "My Dashboard",
"meta": {
"label": "#welcomeDashboard_label",
"pathname": "welcome"
}
}
// General
this.localize.term('general_close')
this.localize.term('general_cancel')
this.localize.term('general_save')
this.localize.term('general_delete')
this.localize.term('general_welcome')
// Actions
this.localize.term('actions_create')
this.localize.term('actions_edit')
this.localize.term('actions_remove')
// Dialogs
this.localize.term('dialog_confirm')
this.localize.term('dialog_cancel')
<!-- Shows the key alias instead of value for troubleshooting -->
<umb-localize key="myExtension_welcomeMessage" debug="true"></umb-localize>
// en.js
export default {
greeting: 'Hello',
};
// da.js (Danish)
export default {
greeting: 'Hej',
};
// Register both
export const manifests = [
{
type: 'localization',
alias: 'My.Localization.En',
meta: { culture: 'en' },
js: () => import('./localization/en.js'),
},
{
type: 'localization',
alias: 'My.Localization.Da',
meta: { culture: 'da' },
js: () => import('./localization/da.js'),
},
];
Localize Controller : Auto-available in Umbraco Elements via this.localize
Translation Keys : Use underscore notation (e.g., general_close, myExtension_welcomeMessage)
Fallback : English (en) is the default fallback when translations are missing - all extensions should, as a minimum, include an 'en' localization manifest
Default text : If unsure whether the localization key exists, or for easier readability, add a default text to <umb-localize key="section_key">Default text</umb-localize> or as second argument to termOrDefault()
Arguments : Pass dynamic values using .args attribute or second parameter to term()
Manifest Localization : Prefix values with # to reference translation keys
Debug Mode : Use debug="true" to show key aliases for troubleshooting
File Structure :
That's it! Always fetch fresh docs, keep examples minimal, generate complete working code.
Weekly Installs
72
Repository
GitHub Stars
14
First Seen
Feb 4, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
github-copilot52
cursor25
opencode24
codex23
gemini-cli22
amp21
2025 Node.js 最佳实践指南:框架选择、架构原则与错误处理
5,500 周安装