Skip to content

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

Merged
JackieTien97 merged 13 commits into
masterfrom
ty/chinese
May 17, 2026
Merged

feat: add compile-time i18n for log and exception messages#17613
JackieTien97 merged 13 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 4.99469% with 894 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.40%. Comparing base (3145e83) to head (a2d4f0e).
⚠️ Report is 1 commits behind head on master.

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 ⚠️
...rc/main/java/org/apache/iotdb/session/Session.java 6.89% 27 Missing ⚠️
...che/iotdb/confignode/manager/ProcedureManager.java 0.00% 23 Missing ⚠️
...rg/apache/iotdb/tool/backup/IoTDBDataBackTool.java 0.00% 20 Missing ⚠️
...ache/iotdb/jdbc/IoTDBAbstractDatabaseMetadata.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 ⚠️
...che/iotdb/confignode/manager/node/NodeManager.java 0.00% 16 Missing ⚠️
...confignode/client/sync/SyncDataNodeClientPool.java 0.00% 13 Missing ⚠️
... and 205 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #17613      +/-   ##
============================================
- Coverage     40.42%   40.40%   -0.03%     
  Complexity     2574     2574              
============================================
  Files          5179     5179              
  Lines        349261   349628     +367     
  Branches      44683    44683              
============================================
+ Hits         141206   141258      +52     
- Misses       208055   208370     +315     

☔ 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
Apply fixes from code review of ty/chinese i18n PR:

- Remove unused PipeMessages.PATH_TRAVERSAL_DETECTED (P0: EN/ZH inconsistency)
- Replace prefix/suffix fragment concatenation with String.format in
  CalcMessages, JdbcMessages, DataNodeQueryMessages so single-placeholder
  format strings are used end-to-end
- Rename short/ambiguous constants: DataNodeQueryMessages.VS -> TYPE_MISMATCH_FMT;
  drop the OF/EXISTS fragments in favour of SOURCE_HANDLE_FOR_PLAN_NODE_EXISTS_FMT
- Shorten three 70+ char constant names in confignode (Manager/Procedure messages)
- Remove unused SessionMessages.REDIRECT_TWICE_EXCEPTION/REDIRECT_TWICE_SUFFIX;
  move local REDIRECT_TWICE/REDIRECT_TWICE_RETRY out of Session.java and split
  into REDIRECT_TWICE_LOG[_WITH_SQL] / REDIRECT_TWICE_MSG[_WITH_SQL] pairs
@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

@JackieTien97 JackieTien97 merged commit f797f85 into master May 17, 2026
28 of 30 checks passed
@JackieTien97 JackieTien97 deleted the ty/chinese branch May 17, 2026 00:11
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