ChinesePinyin

将中文汉字翻译成拼音。「translate chinese hanzi to pinyin」

Github星跟蹤圖

ChinesePinyin

Build Status

Translate chinese hanzi to pinyin.

The dict is borrowed from http://github.com/fayland/perl-lingua-han/tree/master/Lingua-Han-PinYin/

Install

gem install chinese_pinyin

or add in Gemfile.

gem 'chinese_pinyin'

Usage

By CLI

$ ch2py -h
Usage: ch2py [opts]
    -c, --camelcase                  Camelcase of each word
    -i, --stdin                      Read from stdard input
    -t, --tone                       Show tone at end of word
    -m, --tonemarks                  Show tone at top of letter, this
would cover -t option
    -s, --splitter <splitter>        Splitter of each word, use a space
by default
    -v, --version                    Show version
    -h, --help                       Show this help

$ ch2py 中文
zhong wen

By code

require 'chinese_pinyin'

Pinyin.t('中国')  => "zhong guo"
Pinyin.t('你好world') => "ni hao world"
Pinyin.t('中国', splitter: '-') => "zhong-guo"
Pinyin.t('中国', splitter: '') => "zhongguo"
Pinyin.t('中国', tone: true) => "zhong1 guo2"
Pinyin.t('中国', tonemarks: true) => "zhōng guó"
Pinyin.t('北京') {, letters, letters[0].upcase } => 'BJ'
Pinyin.t('北京') {, letters, i, letters[0].upcase if i == 0 } => 'B'

Polyphone Issue

use Words.dat to override default behavior.

by default

Pinyin.t('广州') => "yan zhou"

add file Words.dat

广州, guang3 zhou1

set ENV['WORDS_FILE'] for Words.dat

ENV['WORDS_FILE'] = "Words.dat path"
Pinyin.t('广州') => "guang zhou"

主要指標

概覽
名稱與所有者flyerhzm/chinese_pinyin
主編程語言Ruby
編程語言Ruby (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2010-03-10 14:19:59
推送於2021-04-18 23:30:38
最后一次提交2021-04-19 07:30:25
發布數17
最新版本名稱1.1.0 (發布於 2021-04-19 07:30:33)
第一版名稱v0.1.0 (發布於 )
用户参与
星數427
關注者數19
派生數58
提交數78
已啟用問題?
問題數19
打開的問題數10
拉請求數13
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?