feat(i18n): 统一国际化系统架构,支持插件独立翻译 (#301)
* feat(i18n): 统一国际化系统架构,支持插件独立翻译 ## 主要改动 ### 核心架构 - 增强 LocaleService,支持插件命名空间翻译扩展 - 新增 editor-runtime/i18n 模块,提供 createPluginLocale/createPluginTranslator - 新增 editor-core/tokens.ts,定义 LocaleServiceToken 等服务令牌 - 改进 PluginAPI 类型安全,使用 ServiceToken<T> 替代 any ### 编辑器本地化 - 扩展 en.ts/zh.ts 翻译文件,覆盖所有 UI 组件 - 新增 es.ts 西班牙语支持 - 重构 40+ 组件使用 useLocale() hook ### 插件本地化系统 - behavior-tree-editor: 新增 locales/ 和 useBTLocale hook - material-editor: 新增 locales/ 和 useMaterialLocale hook - particle-editor: 新增 locales/ 和 useParticleLocale hook - tilemap-editor: 新增 locales/ 和 useTilemapLocale hook - ui-editor: 新增 locales/ 和 useUILocale hook ### 类型安全改进 - 修复 Debug 工具使用公共接口替代 as any - 修复 ChunkStreamingSystem 添加 forEachChunk 公共方法 - 修复 blueprint-editor 移除不必要的向后兼容代码 * fix(behavior-tree-editor): 使用 ServiceToken 模式修复服务解析 - 创建 BehaviorTreeServiceToken 遵循"谁定义接口,谁导出Token"原则 - 使用 ServiceToken.id (symbol) 注册服务到 ServiceContainer - 更新 PluginSDKRegistry.resolveService 支持 ServiceToken 检测 - BehaviorTreeEditorPanel 现在使用类型安全的 PluginAPI.resolve * fix(behavior-tree-editor): 使用 ServiceContainer.resolve 获取类注册的服务 * fix: 修复多个包的依赖和类型问题 - core: EntityDataCollector.getEntityDetails 使用 HierarchySystem 获取父实体 - ui-editor: 添加 @esengine/editor-runtime 依赖 - tilemap-editor: 添加 @esengine/editor-runtime 依赖 - particle-editor: 添加 @esengine/editor-runtime 依赖
This commit is contained in:
@@ -18,22 +18,24 @@ class EditorAppearanceEditorModule implements IEditorModuleLoader {
|
||||
async install(services: ServiceContainer): Promise<void> {
|
||||
const settingsRegistry = services.resolve(SettingsRegistry);
|
||||
|
||||
// Register settings using translation keys (prefixed with '$')
|
||||
// 使用翻译键注册设置(以 '$' 为前缀)
|
||||
settingsRegistry.registerCategory({
|
||||
id: 'appearance',
|
||||
title: '外观',
|
||||
description: '配置编辑器的外观设置',
|
||||
title: '$pluginSettings.appearance.title',
|
||||
description: '$pluginSettings.appearance.description',
|
||||
sections: [
|
||||
{
|
||||
id: 'font',
|
||||
title: '字体设置',
|
||||
description: '配置编辑器字体样式',
|
||||
title: '$pluginSettings.appearance.font.title',
|
||||
description: '$pluginSettings.appearance.font.description',
|
||||
settings: [
|
||||
{
|
||||
key: 'editor.fontSize',
|
||||
label: '字体大小 (px)',
|
||||
label: '$pluginSettings.appearance.font.fontSize.label',
|
||||
type: 'range',
|
||||
defaultValue: 13,
|
||||
description: '编辑器界面的字体大小',
|
||||
description: '$pluginSettings.appearance.font.fontSize.description',
|
||||
min: 11,
|
||||
max: 18,
|
||||
step: 1
|
||||
@@ -42,15 +44,15 @@ class EditorAppearanceEditorModule implements IEditorModuleLoader {
|
||||
},
|
||||
{
|
||||
id: 'inspector',
|
||||
title: '检视器设置',
|
||||
description: '配置属性检视器显示',
|
||||
title: '$pluginSettings.appearance.inspector.title',
|
||||
description: '$pluginSettings.appearance.inspector.description',
|
||||
settings: [
|
||||
{
|
||||
key: 'inspector.decimalPlaces',
|
||||
label: '数字小数位数',
|
||||
label: '$pluginSettings.appearance.inspector.decimalPlaces.label',
|
||||
type: 'number',
|
||||
defaultValue: 4,
|
||||
description: '数字类型属性显示的小数位数,设置为 -1 表示不限制',
|
||||
description: '$pluginSettings.appearance.inspector.decimalPlaces.description',
|
||||
min: -1,
|
||||
max: 10,
|
||||
step: 1
|
||||
@@ -59,15 +61,15 @@ class EditorAppearanceEditorModule implements IEditorModuleLoader {
|
||||
},
|
||||
{
|
||||
id: 'scriptEditor',
|
||||
title: '脚本编辑器',
|
||||
description: '配置用于打开脚本文件的外部编辑器',
|
||||
title: '$pluginSettings.appearance.scriptEditor.title',
|
||||
description: '$pluginSettings.appearance.scriptEditor.description',
|
||||
settings: [
|
||||
{
|
||||
key: 'editor.scriptEditor',
|
||||
label: '脚本编辑器',
|
||||
label: '$pluginSettings.appearance.scriptEditor.editor.label',
|
||||
type: 'select',
|
||||
defaultValue: 'system',
|
||||
description: '双击脚本文件时使用的编辑器',
|
||||
description: '$pluginSettings.appearance.scriptEditor.editor.description',
|
||||
options: SettingsService.SCRIPT_EDITORS.map(editor => ({
|
||||
value: editor.id,
|
||||
label: editor.name
|
||||
@@ -75,11 +77,11 @@ class EditorAppearanceEditorModule implements IEditorModuleLoader {
|
||||
},
|
||||
{
|
||||
key: 'editor.customScriptEditorCommand',
|
||||
label: '自定义编辑器命令',
|
||||
label: '$pluginSettings.appearance.scriptEditor.customCommand.label',
|
||||
type: 'string',
|
||||
defaultValue: '',
|
||||
description: '当选择"自定义"时,填写编辑器的命令行命令(如 notepad++)',
|
||||
placeholder: '例如:notepad++'
|
||||
description: '$pluginSettings.appearance.scriptEditor.customCommand.description',
|
||||
placeholder: '$pluginSettings.appearance.scriptEditor.customCommand.placeholder'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -17,22 +17,24 @@ class PluginConfigEditorModule implements IEditorModuleLoader {
|
||||
async install(services: ServiceContainer): Promise<void> {
|
||||
const settingsRegistry = services.resolve(SettingsRegistry);
|
||||
|
||||
// Register settings using translation keys (prefixed with '$')
|
||||
// 使用翻译键注册设置(以 '$' 为前缀)
|
||||
settingsRegistry.registerCategory({
|
||||
id: 'plugins',
|
||||
title: '插件',
|
||||
description: '管理项目使用的插件',
|
||||
title: '$pluginSettings.plugins.title',
|
||||
description: '$pluginSettings.plugins.description',
|
||||
sections: [
|
||||
{
|
||||
id: 'engine-plugins',
|
||||
title: '插件管理',
|
||||
description: '启用或禁用项目需要的插件。禁用不需要的插件可以减少打包体积。',
|
||||
title: '$pluginSettings.plugins.management.title',
|
||||
description: '$pluginSettings.plugins.management.description',
|
||||
settings: [
|
||||
{
|
||||
key: 'project.enabledPlugins',
|
||||
label: '',
|
||||
label: '$pluginSettings.plugins.management.list.label',
|
||||
type: 'pluginList',
|
||||
defaultValue: [],
|
||||
description: ''
|
||||
description: '$pluginSettings.plugins.management.list.description'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -26,60 +26,62 @@ class ProfilerEditorModule implements IEditorModuleLoader {
|
||||
this.messageHub = services.resolve(MessageHub);
|
||||
|
||||
const settingsRegistry = services.resolve(SettingsRegistry);
|
||||
// Register settings using translation keys (prefixed with '$')
|
||||
// 使用翻译键注册设置(以 '$' 为前缀)
|
||||
settingsRegistry.registerCategory({
|
||||
id: 'profiler',
|
||||
title: '性能分析器',
|
||||
description: '配置性能分析器的行为和显示选项',
|
||||
title: '$pluginSettings.profiler.title',
|
||||
description: '$pluginSettings.profiler.description',
|
||||
sections: [
|
||||
{
|
||||
id: 'connection',
|
||||
title: '连接设置',
|
||||
description: '配置WebSocket服务器连接参数',
|
||||
title: '$pluginSettings.profiler.connection.title',
|
||||
description: '$pluginSettings.profiler.connection.description',
|
||||
settings: [
|
||||
{
|
||||
key: 'profiler.port',
|
||||
label: '监听端口',
|
||||
label: '$pluginSettings.profiler.connection.port.label',
|
||||
type: 'number',
|
||||
defaultValue: 8080,
|
||||
description: '性能分析器WebSocket服务器监听的端口号',
|
||||
placeholder: '8080',
|
||||
description: '$pluginSettings.profiler.connection.port.description',
|
||||
placeholder: '$pluginSettings.profiler.connection.port.placeholder',
|
||||
min: 1024,
|
||||
max: 65535,
|
||||
validator: {
|
||||
validate: (value: number) => value >= 1024 && value <= 65535,
|
||||
errorMessage: '端口号必须在1024到65535之间'
|
||||
errorMessage: '$pluginSettings.profiler.connection.port.errorMessage'
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'profiler.autoStart',
|
||||
label: '自动启动服务器',
|
||||
label: '$pluginSettings.profiler.connection.autoStart.label',
|
||||
type: 'boolean',
|
||||
defaultValue: true,
|
||||
description: '编辑器启动时自动启动性能分析器服务器'
|
||||
description: '$pluginSettings.profiler.connection.autoStart.description'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'display',
|
||||
title: '显示设置',
|
||||
description: '配置性能数据的显示选项',
|
||||
title: '$pluginSettings.profiler.display.title',
|
||||
description: '$pluginSettings.profiler.display.description',
|
||||
settings: [
|
||||
{
|
||||
key: 'profiler.refreshInterval',
|
||||
label: '刷新间隔 (毫秒)',
|
||||
label: '$pluginSettings.profiler.display.refreshInterval.label',
|
||||
type: 'range',
|
||||
defaultValue: 100,
|
||||
description: '性能数据刷新的时间间隔',
|
||||
description: '$pluginSettings.profiler.display.refreshInterval.description',
|
||||
min: 50,
|
||||
max: 1000,
|
||||
step: 50
|
||||
},
|
||||
{
|
||||
key: 'profiler.maxDataPoints',
|
||||
label: '最大数据点数',
|
||||
label: '$pluginSettings.profiler.display.maxDataPoints.label',
|
||||
type: 'number',
|
||||
defaultValue: 100,
|
||||
description: '图表中保留的最大历史数据点数量',
|
||||
description: '$pluginSettings.profiler.display.maxDataPoints.description',
|
||||
min: 10,
|
||||
max: 500
|
||||
}
|
||||
|
||||
@@ -58,42 +58,46 @@ class ProjectSettingsEditorModule implements IEditorModuleLoader {
|
||||
// Setup listener for UI design resolution changes
|
||||
this.setupSettingsListener();
|
||||
|
||||
// Register settings using translation keys (prefixed with '$')
|
||||
// 使用翻译键注册设置(以 '$' 为前缀)
|
||||
settingsRegistry.registerCategory({
|
||||
id: 'project',
|
||||
title: '项目',
|
||||
description: '项目级别的配置',
|
||||
title: '$pluginSettings.project.title',
|
||||
description: '$pluginSettings.project.description',
|
||||
sections: [
|
||||
{
|
||||
id: 'ui-settings',
|
||||
title: 'UI 设置',
|
||||
description: '配置 UI 系统的基础参数',
|
||||
title: '$pluginSettings.project.uiSettings.title',
|
||||
description: '$pluginSettings.project.uiSettings.description',
|
||||
settings: [
|
||||
{
|
||||
key: 'project.uiDesignResolution.width',
|
||||
label: '设计宽度',
|
||||
label: '$pluginSettings.project.uiSettings.designWidth.label',
|
||||
type: 'number',
|
||||
defaultValue: 1920,
|
||||
description: 'UI 画布的设计宽度(像素)',
|
||||
description: '$pluginSettings.project.uiSettings.designWidth.description',
|
||||
min: 320,
|
||||
max: 7680,
|
||||
step: 1
|
||||
},
|
||||
{
|
||||
key: 'project.uiDesignResolution.height',
|
||||
label: '设计高度',
|
||||
label: '$pluginSettings.project.uiSettings.designHeight.label',
|
||||
type: 'number',
|
||||
defaultValue: 1080,
|
||||
description: 'UI 画布的设计高度(像素)',
|
||||
description: '$pluginSettings.project.uiSettings.designHeight.description',
|
||||
min: 240,
|
||||
max: 4320,
|
||||
step: 1
|
||||
},
|
||||
{
|
||||
key: 'project.uiDesignResolution.preset',
|
||||
label: '分辨率预设',
|
||||
label: '$pluginSettings.project.uiSettings.resolutionPreset.label',
|
||||
type: 'select',
|
||||
defaultValue: '1920x1080',
|
||||
description: '选择常见的分辨率预设',
|
||||
description: '$pluginSettings.project.uiSettings.resolutionPreset.description',
|
||||
// Resolution preset options use static labels (not localized)
|
||||
// 分辨率预设选项使用静态标签(不本地化)
|
||||
options: UI_RESOLUTION_PRESETS.map(p => ({
|
||||
label: p.label,
|
||||
value: `${p.value.width}x${p.value.height}`
|
||||
@@ -103,17 +107,17 @@ class ProjectSettingsEditorModule implements IEditorModuleLoader {
|
||||
},
|
||||
{
|
||||
id: 'modules',
|
||||
title: '引擎模块',
|
||||
description: '管理项目使用的引擎模块。每个模块包含运行时组件和编辑器工具。禁用不需要的模块可以减小构建体积。',
|
||||
title: '$pluginSettings.project.modules.title',
|
||||
description: '$pluginSettings.project.modules.description',
|
||||
settings: [
|
||||
{
|
||||
key: 'project.disabledModules',
|
||||
label: '模块列表',
|
||||
label: '$pluginSettings.project.modules.list.label',
|
||||
type: 'moduleList',
|
||||
// Default: no modules disabled (all enabled)
|
||||
// 默认:没有禁用的模块(全部启用)
|
||||
defaultValue: [],
|
||||
description: '取消勾选不需要的模块。核心模块不能禁用。新增的模块会自动启用。',
|
||||
description: '$pluginSettings.project.modules.list.description',
|
||||
// Custom props for moduleList type
|
||||
// Modules are loaded dynamically from ModuleRegistry (sizes from module.json)
|
||||
// 模块从 ModuleRegistry 动态加载(大小来自 module.json)
|
||||
|
||||
Reference in New Issue
Block a user