国际化与通知
独立中英文文案、局部覆盖与宿主通知集成。
让文档进入你的工作流
选择语言
createEditor({
el: "#editor",
ui: {
locale: "zh-CN",
},
});内置 en / zh,BCP 47 标签会归一化。默认英文。ui.locale 同时用于界面与 Emoji picker 数据语言,不依赖宿主国际化库。
覆盖文案
ui.messages 为消息树的深度局部覆盖,未覆盖字段回退到内置字典:
import { createEditor, type EditorOptions } from "@musecanto/editor-kit";
const options: EditorOptions = {
el: "#editor",
ui: {
locale: "zh",
messages: { editor: { placeholder: "写下你的想法…" } },
},
};
createEditor(options);插件消息参与合并,宿主 ui.messages 优先。React UI 用 useEditorT(),扩展等非 React 场景用 tEditor();避免硬编码用户可见字符串。
接入宿主 toast
const options = {
notifications: {
builtinToaster: false,
toast: {
success: (title, options) => hostToast.success(title, options),
error: (title, options) => hostToast.error(title, options),
},
onNotify: (event) => reportEditorEvent(event),
},
};hostToast、reportEditorEvent 由宿主实现。builtinToaster: false 只是不挂内置容器;enabled: false 禁用 SDK toast 展示调用,但保留 onNotify。
Emoji 数据
emojibaseUrl 覆盖数据集根地址,加载 ${emojibaseUrl}/${locale}/data.json。默认公开 jsDelivr。自有 CDN 需确认目录结构和 CORS。
多实例语言
翻译器按实例创建,React Provider、占位符和默认通知都使用该实例的语言。非 React 扩展接收自己的 translator;tEditor 的第三个参数可以显式传入该 translator。包内英文文案作为回退,宿主覆盖优先。