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

Ready to merge
JA
7mo ago
+769-175

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 across renderers and the CLI with English, Traditional Chinese (zh-Hant), and Simplified Chinese (zh-CN). Adds a --lang option, CJK-aware console alignment, per-locale HTML lang, and hardens i18n with thread-safe and null-safe handling.

  • 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 translations: messages.properties (en), messages_zh_TW.properties (zh-Hant), messages_zh_CN.properties (zh-CN).
    • Added --lang CLI option (en, zh-Hant, zh-CN), accepts zh-TW/zh-Hans aliases.
    • Implemented CJK-aware display width for proper console alignment.
    • HTML output now sets the lang attribute based on the selected locale.
  • Bug Fixes

    • Prevented NPEs by adding null checks to CJK centering helpers.
    • Made I18n locale and bundle handling thread-safe (volatile fields, synchronized setLocale).