Hi,

+1 !!!

Good feature!  好功能!

Jialin Qiao

Yuan Tian <[email protected]> 于2026年5月7日周四 10:48写道:
>
>   Hi all,
>
>
>
>
>   I'd like to share a PR that adds compile-time internationalization (i18n)
> support for IoTDB's log messages and exception messages:
> https://github.com/apache/iotdb/pull/17613
>
>
>
>
>
>   我想跟大家同步一个 PR,为 IoTDB 的日志消息和异常消息添加了编译时国际化(i18n)支持:
> https://github.com/apache/iotdb/pull/17613
>
>
>   ---
>
>
>
>   Background / 背景
>
>
>
>
>   Currently all log and exception messages in IoTDB are hardcoded in
> English. For Chinese users and enterprise deployments, having localized
> messages would significantly improve the debugging and troubleshooting
> experience. However,
>   traditional runtime i18n (e.g., Java ResourceBundle) introduces runtime
> overhead and additional memory consumption, which is unacceptable for a
> high-performance database.
>
>
>   目前 IoTDB
> 所有的日志和异常消息都是硬编码的英文。对于中文用户和企业级部署场景,本地化的消息能够显著提升调试和排查问题的效率。然而,传统的运行时国际化方案(如
> Java
>   ResourceBundle)会引入运行时开销和额外的内存消耗,这对于高性能数据库来说是不可接受的。
>
>
>
>
>   Approach / 方案
>
>   This PR takes a compile-time approach that achieves zero runtime
> overhead:
>
>
>
>   本 PR 采用编译时方案,实现零运行时开销:
>
>
>
>   - All messages are extracted into public static final String constant
> classes, with separate English and Chinese versions stored under
> src/main/i18n/en/ and src/main/i18n/zh/
>
>   - 所有消息被提取为 public static final String 常量类,英文和中文版本分别存放在 src/main/i18n/en/
> 和 src/main/i18n/zh/ 目录下
>   - A Maven profile (-Pwith-zh-locale) controls which version is compiled.
> The build-helper-maven-plugin adds the corresponding i18n source directory
> as a compile source root
>
>   - 通过 Maven profile(-Pwith-zh-locale)控制编译哪个版本。build-helper-maven-plugin
> 将对应的 i18n 源码目录添加为编译源码根目录
>
>   - Since Java compiler (javac) inlines static final String constants into
> the bytecode at the call site (JLS §13.1), the Messages class is never
> referenced or loaded at runtime — the effect is identical to directly
> writing the
>   string literal in the code
>
>
>
>   - 由于 Java 编译器(javac)会将 static final String 常量内联到调用处的字节码中(JLS
> §13.1),Messages 类在运行时不会被引用或加载——效果等同于直接在代码中写字面量字符串
>
>
>
>
>
>   Build Commands / 构建命令
>
>
>
>
>   mvn clean package -DskipTests                  # English (default) /
> 英文(默认)
>   mvn clean package -DskipTests -Pwith-zh-locale # Chinese / 中文
>
>
>
>
>   Scope / 改动范围
>
>
>
>
>   The PR covers 7 modules with 25 message constant classes (50 files
> including both en and zh) and 4635 string replacements across 1065 files:
>
>
>
>   本 PR 覆盖了 7 个模块,包含 25 个消息常量类(含中英文共 50 个文件),在 1065 个文件中完成了 4635 处字符串替换:
>
>
>
>   ┌───────────────┬──────────────────────────┬────────────────────┐
>
>
>
>   │ Module / 模块                │ Message Classes / 消息类
>  │ Constants / 常量数                     │
>   ├───────────────┼──────────────────────────┼────────────────────┤
>
>
>
>   │ node-commons             │ 10
>                    │ 718                                            │
>   ├───────────────┼──────────────────────────┼────────────────────┤
>   │ datanode                       │ 5
>                           │ 2120                                         │
>   ├───────────────┼──────────────────────────┼────────────────────┤
>   │ confignode                    │ 3
>                           │ 1068                                           │
>   ├───────────────┼──────────────────────────┼────────────────────┤
>   │ consensus                     │ 4
>                          │ 237                                             │
>   ├───────────────┼──────────────────────────┼────────────────────┤
>
>
>
>   │ session                         │ 1
>                             │ 133
>  │
>   ├───────────────┼──────────────────────────┼────────────────────┤
>
>
>
>   │ cli                                   │ 1
>                                  │ 29
>         │
>   ├───────────────┼──────────────────────────┼────────────────────┤
>   │ jdbc                                │ 1
>                                 │ 99
>      │
>   └───────────────┴──────────────────────────┴────────────────────┘
>
>   Key Design Decisions / 关键设计决策
>
>   1. Log messages use {} placeholders (SLF4J native), exception messages
> use %s (String.format) — no custom utility class needed, keeping the
> original style of each usage context.
>
>
>   1. 日志消息使用 {} 占位符(SLF4J 原生),异常消息使用 %s(String.format)
> ——无需自定义工具类,保持各使用场景的原有风格。
>
>   2. One set of constants per subsystem (e.g., StorageEngineMessages,
> DataNodeQueryMessages, PipeMessages) — organized by functional area for
> maintainability.
>
>
>
>
>   2. 按子系统划分常量类(如
> StorageEngineMessages、DataNodeQueryMessages、PipeMessages)——按功能区域组织,便于维护。
>
>
>   3. Third-party code excluded — external/collections4/ (vendored Apache
> Commons code) is left untouched.
>
>
>
>
>
>
>   3. 排除第三方代码 —— external/collections4/(内嵌的 Apache Commons 代码)保持不变。
>
>
>
>
>
>
>   Verification / 验证
>
>
>
>
>   - Both English and Chinese profiles compile successfully (BUILD SUCCESS)
>
>
>
>   - javap -c confirms Chinese strings are directly inlined into bytecode
> (e.g., ldc "%s 不是合法路径")
>   - No runtime behavior change for the default (English) build
>
>
>
>   - 英文和中文 profile 均编译成功(BUILD SUCCESS)
>
>
>   - javap -c 确认中文字符串直接内联到字节码中(如 ldc "%s 不是合法路径")
>
>
>   - 默认(英文)构建的运行时行为无任何变化
>
>
>
>
>
>
>   ---
>
>
>
>   Any feedback or suggestions are welcome. Looking forward to your review!
>
>
>
>
>
>
>
>   欢迎任何反馈和建议,期待大家的 review!
>
>
>
>
>   Best regards,
>   ----------------
>
>
>
>   Yuan Tian

Reply via email to