trad2simp
trad2simp
Traditional Chinese to Simplified Chinese conversion library for Crystal. Reimplements OpenCC's conversion algorithm and dictionary logic.
Features
- Automatic Profile Detection - Detects HK, TW, or Mainland text and selects the right converter
- Standard Traditional → Simplified (
t2s) - Taiwan Traditional → Simplified (
tw2s,tw2spwith idiom conversion) - Hong Kong Traditional → Simplified (
hk2s) - Sequential Conversion Chains matching OpenCC's multi-pass architecture
- Embedded Dictionaries - Zero runtime I/O
Installation
dependencies:
trad2simp:
github: chi-vi/trad2simp
Usage
require "trad2simp"
# Auto-detect and convert (recommended for unknown sources)
Trad2Simp.convert("我用滑鼠在螢幕上看影片") # => "我用鼠标在屏幕上看视频"
# Or detect profile first, then convert
profile = Trad2Simp.detect_profile(sample_text) # => :tw2sp, :hk2s, or :t2s
variant = Trad2Simp.detect_variant(sample_text) # => Detector::Variant enum
# Manual mode selection
Trad2Simp.t2s("開放中文轉換") # => "开放中文转换"
Trad2Simp.tw2s("臺灣") # => "台湾"
Trad2Simp.tw2sp("用滑鼠點選正規表示式") # => "用鼠标点击正则表达式"
Trad2Simp.hk2s("佢哋係咪喺度") # => "他们是不是在这"
Profile Detection
The detector analyzes text for regional markers:
| Profile | Detected When | Example Markers |
|---|---|---|
:tw2sp |
Taiwan vocabulary | 捷運, 便當, 螢幕, 網路, 滑鼠 |
:hk2s |
Cantonese characters | 佢, 係, 唔, 喺, 嘅, 咗 |
:t2s |
Mainland vocab in Traditional | 視頻, 網絡, 方便面, 地鐵 |
License
Apache-2.0 (matches OpenCC dictionary data license)
Repository
trad2simp
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- 6 days ago
- February 5, 2026
License
Other
Links
Synced at
Thu, 05 Feb 2026 01:55:13 GMT
Languages