> ## Documentation Index
> Fetch the complete documentation index at: https://dripart-docs-recommend-assets-api.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 多语言支持

> 了解如何为 ComfyUI 自定义节点添加多语言支持

如果你想要为你的多语言添加支持，可参考本篇文档了解如何添加多语言支持

目前，ComfyUI 支持以下语言：

* 英语（en）
* 简体中文（zh）
* 繁体中文（zh-TW）
* 法语（fr）
* 韩语（ko）
* 俄语（ru）
* 西班牙语（es）
* 日语（ja）

国际化演示示例：[comfyui-wiki/ComfyUI-i18n-demo](https://github.com/comfyui-wiki/ComfyUI-i18n-demo)

## 目录结构

在你的自定义节点下创建 `locales` 文件夹，支持多种翻译文件类型：

```bash theme={null}
your_custom_node/
├── __init__.py
├── your_node.py
└── locales/                    # 国际化文件夹
    ├── en/                    # 英语翻译（推荐作为基准）
    │   ├── main.json          # 通用英文翻译内容
    │   ├── nodeDefs.json      # 英文节点定义翻译
    │   ├── settings.json      # 可选：设置界面翻译
    │   └── commands.json      # 可选：命令翻译
    ├── zh/                    # 中文翻译文件
    │   ├── nodeDefs.json      # 中文节点定义翻译
    │   ├── main.json          # 通用中文翻译内容
    │   ├── settings.json      # 中文设置界面翻译
    │   └── commands.json      # 中文命令翻译
    ├──...

```

## nodeDefs.json - 节点定义翻译

例如下面是一个i18n-demo节点的Python定义示例：

```python theme={null}
class I18nTextProcessor:
    @classmethod
    def INPUT_TYPES(cls):
        return {
            "required": {
                "text": ("STRING", {
                    "multiline": True,
                    "default": "Hello World!",
                    "tooltip": "The original text content to be processed"
                }),
                "operation": (["uppercase", "lowercase", "reverse", "add_prefix"], {
                    "default": "uppercase",
                    "tooltip": "The text processing operation to be executed"
                }),
                "count": ("INT", {
                    "default": 1,
                    "min": 1,
                    "max": 10,
                    "step": 1,
                    "tooltip": "The number of times to repeat the operation"
                }),
            },
            "optional": {
                "prefix": ("STRING", {
                    "default": "[I18N] ",
                    "multiline": False,
                    "tooltip": "The prefix to add to the text"
                }),
            }
        }

    RETURN_TYPES = ("STRING",)
    RETURN_NAMES = ("processed_text",)
    FUNCTION = "process_text"
    CATEGORY = "I18n Demo"
    DESCRIPTION = "A simple i18n demo node that demonstrates text processing with internationalization support"

    def process_text(self, text, operation, count, prefix=""):
        try:
            result = text
            
            for _ in range(count):
                if operation == "uppercase":
                    result = result.upper()
                elif operation == "lowercase":
                    result = result.lower()
                elif operation == "reverse":
                    result = result[::-1]
                elif operation == "add_prefix":
                    result = prefix + result
            
            return (result,)
        except Exception as e:
            print(f"I18nTextProcessor error: {e}")
            return (f"Error: {str(e)}",)
```

则对应的本地化支持的 nodeDefs.json 文件内容应该包含：

```json theme={null}
{
  "I18nTextProcessor": {
    "display_name": "国际化文本处理器",
    "description": "一个简单的国际化演示节点，展示支持国际化的文本处理功能",
    "inputs": {
      "text": {
        "name": "文本输入",
        "tooltip": "待处理的原始文本内容"
      },
      "operation": {
        "name": "操作类型",
        "tooltip": "要执行的文本处理操作",
        "options": {
          "uppercase": "转为大写",
          "lowercase": "转为小写",
          "reverse": "反转文本",
          "add_prefix": "添加前缀"
        }
      },
      "count": {
        "name": "重复次数",
        "tooltip": "操作重复执行的次数"
      },
      "prefix": {
        "name": "前缀文本",
        "tooltip": "要添加到文本前的前缀"
      }
    },
    "outputs": {
      "0": {
        "name": "处理后文本",
        "tooltip": "最终处理后的文本结果"
      }
    }
  }
}
```

对于节点输出部分，并不采用对应的输出名称，而是使用对应的输出 index 索引，比如第一个输出应为 `0`, 第二个输出为 `1`, 以此类推。

## 菜单设置项目

如在 i18n-demo 节点中我们注册了对应的下面两个菜单设置

```javascript theme={null}
app.registerExtension({
    name: "I18nDemo",
    settings: [
        {
            id: "I18nDemo.EnableDebugMode",
            category: ["I18nDemo","DebugMode"], // This matches the settingsCategories key in main.json
            name: "Enable Debug Mode", // Will be overridden by translation
            tooltip: "Show debug information in console for i18n demo nodes", // Will be overridden by translation
            type: "boolean",
            defaultValue: false,
            experimental: true,
            onChange: (value) => {
                console.log("I18n Demo:", value ? "Debug mode enabled" : "Debug mode disabled");
            }
        },
        {
            id: "I18nDemo.DefaultTextOperation",
            category: ["I18nDemo","DefaultTextOperation"], // This matches the settingsCategories key in main.json
            name: "Default Text Operation", // Will be overridden by translation
            tooltip: "Default operation for text processor node", // Will be overridden by translation
            type: "combo",
            options: ["uppercase", "lowercase", "reverse", "add_prefix"],
            defaultValue: "uppercase",
            experimental: true
        }
    ],
    })
```

如果你需要增加对应国际化支持，对于菜单分类你需要在 `main.json` 中添加

```json theme={null}
{
  "settingsCategories": {
    "I18nDemo": "I18n Demo",
    "DebugMode": "Debug Mode",
    "DefaultTextOperation": "Default Text Operation"
  }
}
```

对于对应的设置项的翻译，建议单独更新在 `settings.json` 中，比如：

```json theme={null}
{
  "I18nDemo_EnableDebugMode": {
    "name": "启用调试模式",
    "tooltip": "在控制台显示国际化演示节点的调试信息"
  },
  "I18nDemo_DefaultTextOperation": {
    "name": "默认文本操作",
    "tooltip": "文本处理节点的默认操作",
    "options": {
      "uppercase": "大写",
      "lowercase": "小写",
      "reverse": "反转",
      "add_prefix": "添加前缀"
    }
  }
}
```

注意对应的翻译 key 的名称应该将原来 id 中的 `.` 替换为 `_`如：

```
"I18nDemo.EnableDebugMode" -> "I18nDemo_EnableDebugMode"
```

## 自定义前端组件本地化支持

\[待更新]
