Han(汉)
a module for tanslating Chinese(汉字) into pinyin.
Installation
$ npm install han
Usage
1. han.letter()
han
Use the letter
method to translate Chinese in to english letter:
var han = ; han // zhongwenhan // zhong-wenhan
The letter
method has 3 params by default, they can all be optional, it depends on you(^^). follow the message below, you can also find it at lib/translate.js:
/* @param `chinese` {String} Chinese word * @param [optional] `separator` {String} separator for the letters * @param [optional] `callback(err, result)` {Function} if a callback is specified, * the program will use an async way to do the translation */
2. han.pinyin(chinese)
User the pinyin
method to translate Chinese into Pinyin(letters with notation):
han // [ [ 'zhōng', 'zhòng' ], [ 'wén', 'wèn' ] ] // mixin are allowed, like:han;// [ 'My Chinese name is ', [ 'xǐao' ], [ 'yú' ], '(sofish)' ] // also running with messy code, see the testcase below
WHY the return value is an array?
Beause that a Chinese word always having more than one pronunciation. You may want to allow users to correct your output that is generated by your program in an automatic way(like google?! yep!).
Testcase
$ npm install han# or git clone git://github.com/sofish/han.git $ cd node_modules/han && node testcase.js
Translating Messy Code
Messy code? orginal file is here testcase.js:
var han = ; consoleconsole// orginal:要实现 Speaker Deck 那种中文转拼音的// yao-shi-xian-speaker-deck-na-zhong-zhong-wen-zhuan-pin-yin-de han; han; consoleconsole// original: My Chinese name is 小鱼(sofish)// [ 'My Chinese name is ', [ 'xǐao' ], [ 'yú' ], '(sofish)' ] consoleconsole// original: #$%^&*中23¢∞§¶•ª52849文@#$%^&*(意思,还有英文:english// [ '#$%^&*', [ 'zhōng', 'zhòng' ], '23¢∞§¶•ª52849', [ 'wén', 'wèn' ],// '@#$%^&*(', [ 'yì' ], [ 'sī', 'sì', 'sāi' ], ',', [ 'húan', 'hái', 'xúan' ],// [ 'yǒu', 'yòu' ], [ 'yīng', 'yāng' ], [ 'wén', 'wèn' ], ':english' ]
License
Licensed under MIT.
Contributers:
Specail thank to fayland for providing the unicode table of Chinese.