HenryQW/OpenCC.henry.wang

How to translate simplified Chinese to traditional Chinese?

jhangyu opened this issue · 1 comments

Hi, thanks for building this opencc api docker image

I'm a traditional chinese user, I just curious about is there are any settings to translate simplified to traditional chinese rather than traditional chinese to simplified chinese?

Thanks for reply!

There isn't one atm, but it's entirely possible and I will take a look when I'm free.

Since OpenCC supports multiple ways for conversion:

  • s2t.json Simplified Chinese to Traditional Chinese 簡體到繁體
  • t2s.json Traditional Chinese to Simplified Chinese 繁體到簡體
  • s2tw.json Simplified Chinese to Traditional Chinese (Taiwan Standard) 簡體到臺灣正體
  • tw2s.json Traditional Chinese (Taiwan Standard) to Simplified Chinese 臺灣正體到簡體
  • s2hk.json Simplified Chinese to Traditional Chinese (Hong Kong Standard) 簡體到香港繁體(香港小學學習字詞表標準)
  • hk2s.json Traditional Chinese (Hong Kong Standard) to Simplified Chinese 香港繁體(香港小學學習字詞表標準)到簡體
  • s2twp.json Simplified Chinese to Traditional Chinese (Taiwan Standard) with Taiwanese idiom 簡體到繁體(臺灣正體標準)並轉換爲臺灣常用詞彙
  • tw2sp.json Traditional Chinese (Taiwan Standard) to Simplified Chinese with Mainland Chinese idiom 繁體(臺灣正體標準)到簡體並轉換爲中國大陸常用詞彙
  • t2tw.json Traditional Chinese (OpenCC Standard) to Taiwan Standard 繁體(OpenCC 標準)到臺灣正體
  • t2hk.json Traditional Chinese (OpenCC Standard) to Hong Kong Standard 繁體(OpenCC 標準)到香港繁體(香港小學學習字詞表標準)

I propose the followings:

  1. By default it uses t2s, as it is now.
  2. Posting to corresponding routes, eg. http://localhost:3000/tw2s, will pick up the desired conversion.

Also I don't enjoy coding in PHP so I won't be providing per feed settings for the plugin.

I'm not an expert in unicode conversion thus I'm not sure if the exisitng way of handling them will work for Traditional Chinese:

const reconvert = str =>
str
.replace(/(\\u)(\w{1,4})/gi, $0 =>
String.fromCharCode(
parseInt(escape($0).replace(/(%5Cu)(\w{1,4})/g, "$2"), 16)
)
)
.replace(/(&#x)(\w{1,4});/gi, $0 =>
String.fromCharCode(
parseInt(escape($0).replace(/(%26%23x)(\w{1,4})(%3B)/g, "$2"), 16)
)
)
.replace(/(&#)(\d{1,6});/gi, $0 =>
String.fromCharCode(
parseInt(escape($0).replace(/(%26%23)(\d{1,6})(%3B)/g, "$2"), 16)
)
);