Skip to content

feat: add i18n support with zh-Hant and zh-CN translations#899

Open
Jacky97s wants to merge 3 commits intoOpenAPITools:masterfrom
Jacky97s:master
Open

feat: add i18n support with zh-Hant and zh-CN translations#899
Jacky97s wants to merge 3 commits intoOpenAPITools:masterfrom
Jacky97s:master

Conversation

@Jacky97s
Copy link

@Jacky97s Jacky97s commented Mar 20, 2026

Summary

  • Add I18n utility class with UTF-8 ResourceBundle loading and locale parsing
  • Extract all user-facing strings from renderers (Console, Markdown, HTML, AsciiDoc) into .properties resource bundles
  • Add --lang CLI option to select output language (en, zh-Hant, zh-CN)
  • Add CJK-aware display width calculation for correct console alignment with Chinese characters
  • Add Traditional Chinese (zh-TW) and Simplified Chinese (zh-CN) translation files
  • Set HTML lang attribute dynamically based on locale

Usage

# Default (English)
openapi-diff old.yaml new.yaml

# Traditional Chinese
openapi-diff old.yaml new.yaml --lang zh-Hant

# Simplified Chinese
openapi-diff old.yaml new.yaml --lang zh-CN

Test plan

  • All 266 existing tests pass with default English locale
  • Verify console output alignment with Chinese characters
  • Verify HTML output includes correct lang attribute for each locale
  • Verify --lang CLI option selects correct translations

Summary by cubic

Add internationalization to all renderers and the CLI, with English, Traditional Chinese (zh-Hant), and Simplified Chinese (zh-CN) output. Adds a --lang option, fixes console centering for CJK, and sets the HTML lang attribute per locale.

  • New Features
    • Introduced I18n utility with UTF-8 ResourceBundle loading and locale parsing.
    • Replaced hardcoded strings in Console/Markdown/HTML/AsciiDoc with bundle messages.
    • Added translation files: messages.properties (en), messages_zh_TW.properties (zh-Hant), messages_zh_CN.properties (zh-CN).
    • Added --lang CLI option to select output language (en, zh-Hant, zh-CN), defaulting to en.
    • Implemented CJK-aware display width for proper console alignment with Chinese characters.
    • HTML output now sets the lang attribute based on the selected locale.

Written for commit b08e836. Summary will update on new commits.

- Add I18n utility class with UTF-8 ResourceBundle loading and locale parsing
- Add English messages.properties as default resource bundle
- Replace hardcoded strings in ConsoleRender, MarkdownRender, HtmlRender, AsciidocRender with I18n.getMessage() calls
- Add CJK-aware display width calculation for correct console alignment
- Add --lang CLI option to select output language
- Set HTML lang attribute dynamically based on locale
- Add messages_zh_TW.properties with full Traditional Chinese translations
…upport

- Add messages_zh_CN.properties with full Simplified Chinese translations
- Add zh-Hant, zh-TW, zh-Hans, zh-CN locale parsing to I18n
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 10 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="core/src/main/java/org/openapitools/openapidiff/core/output/ConsoleRender.java">

<violation number="1" location="core/src/main/java/org/openapitools/openapidiff/core/output/ConsoleRender.java:362">
P2: New CJK centering helper is not null-safe and can throw NPE during rendering/formatting.</violation>
</file>

<file name="core/src/main/java/org/openapitools/openapidiff/core/output/I18n.java">

<violation number="1" location="core/src/main/java/org/openapitools/openapidiff/core/output/I18n.java:20">
P2: `I18n` uses unsynchronized mutable static locale/bundle state, which is not thread-safe and can leak or mismatch language state across concurrent operations.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.


static int displayWidth(String text) {
int width = 0;
for (int i = 0; i < text.length(); i++) {
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 20, 2026

Choose a reason for hiding this comment

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

P2: New CJK centering helper is not null-safe and can throw NPE during rendering/formatting.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At core/src/main/java/org/openapitools/openapidiff/core/output/ConsoleRender.java, line 362:

<comment>New CJK centering helper is not null-safe and can throw NPE during rendering/formatting.</comment>

<file context>
@@ -329,10 +350,48 @@ public String title(String title, char ch) {
+
+  static int displayWidth(String text) {
+    int width = 0;
+    for (int i = 0; i < text.length(); i++) {
+      char c = text.charAt(i);
+      if (isFullWidth(c)) {
</file context>
Fix with Cubic

private I18n() {}

public static void setLocale(Locale locale) {
currentLocale = locale;
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 20, 2026

Choose a reason for hiding this comment

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

P2: I18n uses unsynchronized mutable static locale/bundle state, which is not thread-safe and can leak or mismatch language state across concurrent operations.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At core/src/main/java/org/openapitools/openapidiff/core/output/I18n.java, line 20:

<comment>`I18n` uses unsynchronized mutable static locale/bundle state, which is not thread-safe and can leak or mismatch language state across concurrent operations.</comment>

<file context>
@@ -0,0 +1,72 @@
+  private I18n() {}
+
+  public static void setLocale(Locale locale) {
+    currentLocale = locale;
+    bundle = loadBundle(locale);
+  }
</file context>
Fix with Cubic

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.

1 participant