跳转到内容

编辑器按钮模块

此模块允许向编辑器添加按钮,这些按钮作用于同一应用的另一个模块。

编辑器按钮位置:

  • header-right:编辑器标题栏的右上角
  • header-left:编辑器标题栏的左上角
  • menu:编辑器主菜单中的应用菜单
  • translation-toolbar:带有当前翻译操作的工具栏
  • strings-menu:当前选定字符串的菜单

按钮可以执行以下操作之一:

  • 在编辑器的右侧面板中打开指定的应用模块(参见编辑器右侧面板模块)
  • 在模态对话框中打开指定的应用模块(参见模态模块)
  • 向指定的应用模块发送 editor.button.click 事件

panel 和 modal 类型在每个位置都可用。 event 类型在 translation-toolbar 和 strings-menu 位置可用。

panel 或 event 按钮仅在其目标模块也声明的编辑器模式中出现,因此请将按钮的 modes 保持在目标模块的范围内。 modal 按钮仅取决于其自身的 modes。

标题栏位置和翻译工具栏各自最多显示四个按钮,其余的在更多应用操作下拉菜单中可用。在 assets 模式下,按钮在 header-right、header-left 和 menu 位置可用。在移动端,按钮在 menu、translation-toolbar 和 strings-menu 位置可用,翻译工具栏一次显示一个按钮。

编辑器按钮也列在编辑器的命令面板中,每个按钮都可以在帮助 > 键盘快捷键中分配键盘快捷键。

您可以将此模块的访问权限授予以下用户类别之一:

对于 Crowdin:

  • 仅限我自己(即项目所有者)
  • 本人、项目管理员和开发者
  • 所有项目成员
  • 选定用户

对于 Crowdin 企业版:

  • 仅限组织管理员
  • 组织管理员、项目管理员和开发者
  • 组织项目中的所有用户
  • 选定用户

按钮在编辑器的右侧面板中打开指定的模块。

manifest.json
{
"modules": {
"editor-button": [
{
"key": "editor-button-key",
"name": "Name of Editor Button",
"logo": "/editor-button-logo.png",
"modes": [
"translate"
],
"options": {
"location": "header-right",
"type": "panel",
"module": "editor-panel-module-key",
"weight": 10
}
}
],
"editor-right-panel": [
{
"key": "editor-panel-module-key",
"name": "New Panel",
"modes": [
"translate"
],
"url": "/editor-page"
}
]
}
}

按钮在模态对话框中打开指定的模块。

manifest.json
{
"modules": {
"editor-button": [
{
"key": "editor-button-key",
"name": "Name of Editor Button",
"modes": [
"translate"
],
"options": {
"location": "menu",
"type": "modal",
"module": "modal-module-key"
}
}
],
"modal": [
{
"key": "modal-module-key",
"name": "New Modal",
"url": "/path/to/modal/module"
}
]
}
}

按钮向指定的模块发送 editor.button.click 事件而不打开它。

manifest.json
{
"modules": {
"editor-button": [
{
"key": "editor-button-key",
"name": "Name of Editor Button",
"modes": [
"translate"
],
"options": {
"location": "translation-toolbar",
"type": "event",
"module": "editor-panel-module-key"
}
}
],
"editor-right-panel": [
{
"key": "editor-panel-module-key",
"name": "New Panel",
"modes": [
"translate"
],
"url": "/editor-page"
}
]
}
}

事件载荷取决于按钮的位置。有关对象结构,请参见支持的事件。

key

类型: string

必需: 是

描述: Crowdin 应用内的模块标识符。
它必须不同于应用的 editor-right-panel、editor-background-worker 和 modal 模块的键。

name

类型: string

必需: 是

描述: 显示在按钮工具提示中以及菜单中项目标签的用户可读名称。

logo

类型: string

描述: 按钮图标的相对 URL。
图标以 16x16 像素显示。如果省略,按钮使用应用的徽标。

modes

类型: array

必填: 是

允许的值: translate、comfortable、side-by-side、multilingual、review、assets

描述: 模块将在其中可用的编辑器模式列表。
使用 translate 使模块在以下视图中可用:comfortable、side-by-side 和 multilingual。
如需更精细的控制,请直接指定一个或多个这些值。
review 模式仅在 Crowdin Enterprise 中可用,且仅适用于源文本审核工作流步骤。
assets 模式用于在编辑器中管理资产。

options.location

类型: string

必需: 是

允许值: header-right、header-left、menu、translation-toolbar、strings-menu

描述: 编辑器中添加按钮的位置。

options.type

类型: string

必需: 是

允许值: panel、modal、event

描述: 此按钮将执行的操作类型。
event 类型在 translation-toolbar 和 strings-menu 位置受支持。

options.module

类型: string

必需: 是

描述: 按钮所作用模块的 key。该模块必须在同一应用中声明,并且两者必须至少共享一个 environments 值。
对于 panel 类型使用 editor-right-panel 模块,对于 modal 类型使用 modal 模块,对于 event 类型使用 editor-right-panel 或 editor-background-worker 模块。

options.weight

类型: integer

描述: 同一位置中按钮相对于其他按钮的顺序。值较低的按钮排在前面:在标题栏和翻译工具栏中靠左,在菜单中靠上。
默认值为 100。

environments

类型: string

允许值: crowdin、crowdin-enterprise

描述: 可安装该模块的环境集合。
此参数在跨产品的应用程序中必需。

应用可以在编辑器打开时更新自己的按钮:设置图标、添加徽章、覆盖工具提示或使按钮处于非活动状态。使用 AP.editor.updateButton 方法应用更改,使用 AP.editor.resetButton 将按钮恢复到清单中声明的状态。

本页面对你有帮助吗?