Need help with chinese_pinyin?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

flyerhzm
424 Stars 60 Forks MIT License 78 Commits 9 Opened issues

Description

translate chinese hanzi to pinyin

Services available

!
?

Need anything else?

Contributors list

# 28,944
Ruby
GitHub
actions...
data-ur...
40 commits
# 291,162
C
Objecti...
5 commits
# 487,491
Ruby
5 commits
# 28,864
JavaScr...
vuejs2
Vue.js
vuex
5 commits
# 23,738
Koa
pinyin
Rails
C
2 commits
# 516,540
Ruby
CSS
Shell
2 commits
# 90,199
Ruby
JavaScr...
Shell
full-te...
1 commit
# 19,912
Redis
batch-s...
ubuntu-...
Crystal
1 commit
# 224,901
JavaScr...
Shell
HTML
Elixir
1 commit

ChinesePinyin

Chinese Pinyin

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 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"

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.