alste
alste

Reputation: 1455

Using iconv to convert Traditional Chinese to Simplified Chinese

How do I use the iconv in Ruby to convert a string from Simplified Chinese to Traditional Chinese (and vice-versa)?

I've tried

Iconv.conv("gb2312//IGNORE", "big5//IGNORE", '大家一起學中文')

I get an entirely different string. I've tried with the GBK and BIG5 encodings, I get an IllegalSequence Error.

Thanks.

Upvotes: 1

Views: 2594

Answers (3)

OpenCC

https://github.com/BYVoid/OpenCC

As of 2021, this sees to be the most popular choice:

sudo apt install opencc
opencc -i input.txt -o output.txt -c t2s.json

With:

input.txt

大家一起學中文

we get:

output.txt

大家一起学中文

It also has APIs for several languages like Python and Node.js.

Tested on Ubuntu 21.04, opencc 1.1.1.

Upvotes: 0

erinata
erinata

Reputation: 41

https://rubygems.org/gems/tradsim

I just wrote a gem

To install the gem

gem install tradsim

To use the gem

# encoding: UTF-8
require 'tradsim'
puts Tradsim::to_sim("大家一起學中文")

it will yield

大家一起学中文

and you can use Tradsim::to_trad to do the reverse.

Upvotes: 4

Marnen Laibow-Koser
Marnen Laibow-Koser

Reputation: 6337

Are you trying to convert, say, 學 to 学? I could be wrong, but I don't think Iconv will perform that type of conversion.

Upvotes: 0

Related Questions