Skip to content

feat: add compile-time i18n for log and exception messages#17613

Open
JackieTien97 wants to merge 12 commits into
masterfrom
ty/chinese
Open

feat: add compile-time i18n for log and exception messages#17613
JackieTien97 wants to merge 12 commits into
masterfrom
ty/chinese

Conversation

@JackieTien97
Copy link
Copy Markdown
Contributor

@JackieTien97 JackieTien97 commented May 7, 2026

Summary

  • Add Maven-based compile-time i18n infrastructure that switches between English and Chinese message constants via -Pwith-zh-locale profile
  • Zero runtime overhead: public static final String constants are inlined by javac into bytecode
  • Create 25 message constant classes (en + zh = 50 files) across 7 modules
  • Replace 4635 hardcoded log/exception message strings with compile-time constants

Build commands

mvn clean package -DskipTests                  # English (default)
mvn clean package -DskipTests -Pwith-zh-locale # Chinese

Design

  • Each module has src/main/i18n/en/ and src/main/i18n/zh/ directories with same-package same-class message constant files
  • build-helper-maven-plugin adds src/main/i18n/${i18n.locale} as compile source root
  • Log messages use {} (SLF4J), exception messages use %s (String.format) or plain strings
  • Language determined at compile time, not runtime — no ResourceBundle, no reflection

Modules covered

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

Test plan

  • mvn compile with default (en) profile — BUILD SUCCESS
  • mvn compile -Pwith-zh-locale — BUILD SUCCESS
  • javap -c verification: Chinese strings inlined directly into bytecode
  • Integration test with Chinese build

Add Maven-based compile-time internationalization infrastructure that
switches between English and Chinese message constants via profile,
with zero runtime overhead (javac inlines static final String constants).

Build commands:
  mvn clean package -DskipTests                  # English (default)
  mvn clean package -DskipTests -Pwith-zh-locale # Chinese

Infrastructure:
- Add i18n.locale property (default: en) and with-zh-locale profile
- Configure build-helper-maven-plugin to add src/main/i18n/${i18n.locale}
  as additional source directory

Message constant classes (25 en + 25 zh = 50 files):
- node-commons: AuthMessages, ClientMessages, CommonMessages,
  ConfigMessages, PathMessages, PipeMessages, QueryMessages,
  SchemaMessages, ServiceMessages, UtilMessages
- datanode: StorageEngineMessages, DataNodeQueryMessages,
  DataNodePipeMessages, DataNodeSchemaMessages, DataNodeMiscMessages
- confignode: ConfigNodeMessages, ManagerMessages, ProcedureMessages
- consensus: ConsensusMessages, IoTConsensusMessages,
  IoTConsensusV2Messages, RatisMessages
- session: SessionMessages
- cli: CliMessages
- jdbc: JdbcMessages

4635 hardcoded strings replaced with compile-time constants across
7 modules.
@JackieTien97 JackieTien97 requested a review from Copilot May 7, 2026 03:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

❌ Patch coverage is 5.17621% with 861 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.39%. Comparing base (3145e83) to head (4f2c38e).

Files with missing lines Patch % Lines
...ava/org/apache/iotdb/session/pool/SessionPool.java 6.29% 119 Missing ⚠️
...in/java/org/apache/iotdb/jdbc/IoTDBConnection.java 0.00% 34 Missing ⚠️
...rg/apache/iotdb/tool/backup/IoTDBDataBackTool.java 0.00% 20 Missing ⚠️
...ache/iotdb/jdbc/IoTDBAbstractDatabaseMetadata.java 0.00% 20 Missing ⚠️
...che/iotdb/confignode/manager/ProcedureManager.java 0.00% 20 Missing ⚠️
...ain/java/org/apache/iotdb/jdbc/IoTDBStatement.java 13.63% 19 Missing ⚠️
...tor/process/window/partition/frame/RangeFrame.java 0.00% 18 Missing ⚠️
...rc/main/java/org/apache/iotdb/session/Session.java 12.50% 14 Missing ⚠️
...he/iotdb/confignode/persistence/pipe/PipeInfo.java 0.00% 13 Missing ⚠️
...egation/ApproxPercentileWithWeightAccumulator.java 0.00% 12 Missing ⚠️
... and 208 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #17613      +/-   ##
============================================
- Coverage     40.42%   40.39%   -0.04%     
  Complexity     2574     2574              
============================================
  Files          5179     5179              
  Lines        349261   349543     +282     
  Branches      44683    44683              
============================================
- Hits         141206   141204       -2     
- Misses       208055   208339     +284     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add compile-time i18n message constants for service-rpc, calc-commons,
library-udf, udf-api, metrics/interface, metrics/core, subscription,
isession, mqtt, rest, pipe-api, and trigger-api modules.
…sus, confignode, session, and partial node-commons/datanode
…ssages

- Replace ~230 hardcoded strings with i18n constants across all target modules
- Modules covered: datanode, confignode, node-commons, consensus, calc-commons
- Add Chinese translations for all new constants in zh locale files
- Add CI compile check for Chinese locale build
- Update README/README_ZH/CLAUDE.md with Chinese build instructions
- Both EN and ZH locale compilation verified
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants