Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chinese_pinyin

Package Overview
Dependencies
Maintainers
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chinese_pinyin

  • 1.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
3
Created
Source

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

FAQs

Package last updated on 18 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc