Skip to content

国际化(i18n)

编辑器提供 175+ 个可翻译 label key,覆盖所有 UI 元素。默认文案为中文,并提供完整中文 labels 预设。

使用中文文案

vue
<script setup>
import { EmailEditor, ZH_LABELS } from "@fpfe-group/email-editor-ai";
import "@fpfe-group/email-editor-ai/style.css";
</script>

<template>
  <EmailEditor :labels="ZH_LABELS" />
</template>

局部覆盖

你不需要一次性翻译全部文案,只传入需要修改的 key 即可:

vue
<EmailEditor
  :labels="{
    editor_title: 'Mein Editor',
    undo: 'Ruckgangig',
    redo: 'Wiederholen',
    blocks: 'Bausteine',
  }"
/>

缺失的 key 会回退到默认中文文案。

创建完整翻译

完整翻译可以实现 EditorLabels 接口:

ts
import type { EditorLabels } from "@fpfe-group/email-editor-ai";

export const DE_LABELS: Partial<EditorLabels> = {
  // Toolbar
  blocks: "Bausteine",
  styles: "Stile",
  layers: "Ebenen",
  search_blocks: "Bausteine suchen...",
  undo: "Ruckgangig",
  redo: "Wiederholen",

  // Block categories
  category_layout: "Layout",
  category_content: "Inhalt",
  category_composite: "Fertige",

  // Content blocks
  block_content_text: "Text",
  block_content_image: "Bild",
  block_content_button: "Schaltflache",

  // ... 170+ more keys
};

Label 分类

文案按功能分组:

分类数量示例
Toolbar16blocksundoredocodefullscreen
Block categories4category_layoutcategory_content
Layout blocks6block_layout_1_colblock_layout_2_col
Content blocks7block_content_textblock_content_image
Composite blocks28block_comp_headerblock_comp_hero_banner
Node types13node_mj_textnode_mj_section
Property groups10group_backgroundgroup_spacing
Property labels34prop_background_colorprop_font_family
Property options26align_leftborder_solidmode_horizontal
UI 操作7delete_nodeduplicate_nodemove_up
全局样式11global_stylesemail_background
行内工具栏11bolditaliclinktext_color_label
状态3loadingempty_canvas_hint

访问默认 Labels

ts
import { DEFAULT_LABELS, ZH_LABELS } from "@fpfe-group/email-editor-ai";

// 默认中文文案
console.log(DEFAULT_LABELS.blocks); // '区块'

// 中文预设
console.log(ZH_LABELS.blocks); // '区块'

插件中的 Labels

插件上下文中也可以拿到当前 labels,因此插件可以复用宿主应用的翻译:

ts
const myPlugin: Plugin = (ctx) => {
  // 响应式访问当前 labels
  const currentLabels = ctx.labels.value;

  ctx.registerBlock({
    id: "my-block",
    label: "my_block_label", // 使用 key
    category: "content",
    icon: "Star",
    factory: () => createText("Hello"),
  });
};

基于 MIT License 发布,©FPFE — 保留所有权利。
开源不易,且行且珍惜。