JackieTien97 opened a new pull request, #820:
URL: https://github.com/apache/tsfile/pull/820

   ## Summary
   
   - Adds runtime `ResourceBundle`-based i18n for all log and exception 
messages in `java/common`, `java/tsfile`, and `java/tools`
   - A single published JAR supports both English (default) and Simplified 
Chinese; locale is selected at JVM startup via `-Dtsfile.locale=zh` or 
`Locale.getDefault()`
   - 521 message keys, ~900+ call sites migrated across ~110 files
   - Includes complete Simplified Chinese translation
   - Drift-prevention unit tests enforce key-set alignment between 
`messages.properties` and `messages_zh.properties` at build time
   
   ## Why runtime (vs. compile-time profile)
   
   IoTDB's recent i18n PR 
([apache/iotdb#17613](https://github.com/apache/iotdb/pull/17613)) uses a Maven 
profile to inline locale-specific strings into the JAR at compile time. TsFile 
cannot adopt that same model without either publishing two artifacts per 
release or forking the version, since downstreams (IoTDB and others) consume 
tsfile as a versioned dependency. A runtime ResourceBundle approach keeps a 
single published artifact while letting downstream IoTDB switch locale via a 
JVM startup option.
   
   Locale resolution order at JVM startup (once at class load):
   1. `-Dtsfile.locale=<tag>` system property (e.g. `zh`, `zh-CN`)
   2. `Locale.getDefault()`
   3. English fallback via `ResourceBundle`'s root-bundle mechanism
   
   ## Architecture
   
   - `org.apache.tsfile.i18n.Messages` (in `java/common`) provides `get(key)` 
for SLF4J patterns (`{}` placeholders) and `format(key, args)` for exception 
patterns (`%1$s` positional placeholders).
   - A custom `ResourceBundle.Control` loads `.properties` files as UTF-8 (Java 
8 default is ISO-8859-1) so Chinese characters can be written directly without 
`\uXXXX` escapes.
   - Resources live at 
`java/common/src/main/resources/org/apache/tsfile/i18n/messages.properties` 
(English, root bundle) and `messages_zh.properties` (Chinese).
   - `MessagesTest` enforces key-set alignment + all values non-empty in both 
locales.
   - Technical terms (`TsFile`, `Chunk`, `Page`, `Schema`, class/method names, 
type names, codec names like `RLE`/`GORILLA`) are kept in English in Chinese 
translations, matching IoTDB's convention.
   
   ## IoTDB integration
   
   IoTDB's Chinese build (the `with-zh-locale` profile in apache/iotdb#17613) 
should add `-Dtsfile.locale=zh` to its startup scripts (e.g. 
`start-datanode.sh`, `start-confignode.sh`) to also receive Chinese messages 
from tsfile. No coordinated release is required — IoTDB can adopt this whenever 
convenient.
   
   ## Migration scope
   
   Migrated all literal-string log and exception messages in:
   
   | Module | Keys added |
   |--------|------------|
   | `common` | 16 |
   | `tsfile/write` | 70 |
   | `tsfile/read/common` | 51 |
   | `tsfile/read` (rest) | 84 |
   | `tsfile/encoding` | 58 |
   | `tsfile/file` | 17 |
   | `tsfile/external` | 65 |
   | `tsfile/encrypt` | 13 |
   | `tsfile/compress` | 7 |
   | `tsfile/fileSystem` | 41 |
   | `tsfile/utils` | 37 |
   | `tools` | 61 |
   | **Total** | **521** (incl. 1 seed) |
   
   Each migration commit is its own logical scope so reviewers can review 
per-area.
   
   Sites correctly skipped (not migrated):
   - Variable/data-only constructor args: `throw new X(deviceId.toString())`, 
`throw new X(String.valueOf(type))`, `throw new X(getClass().getName())`
   - Exception wrapping with no message: `throw new X(e)`
   - No-arg throws: `throw new X()`
   - Utility methods that pass through caller-supplied format strings (e.g. 
`Validate.isTrue(boolean, String, Object...)`)
   
   ## Test plan
   
   - [x] All existing tests pass under default (English) locale: `./mvnw test 
-P with-java`
   - [x] `MessagesTest` drift-prevention tests pass — verifies en/zh key set 
alignment + all values non-empty
   - [x] `MessagesTest` passes under `-Duser.language=zh -Duser.country=CN` 
(simulated Chinese locale)
   - [x] Spot tests under `-Dtsfile.locale=zh` show Chinese output without test 
failures
   - [x] `./mvnw spotless:check -P with-java` clean
   - [x] Key count verified: 521 keys in each `.properties` file


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to