All Projects → wxianfeng → hanzi_to_pinyin

wxianfeng / hanzi_to_pinyin

Licence: MIT license
✍️ Chinese Hanzi To Pinyin, Writen In Ruby

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to hanzi to pinyin

Guido blog translation
翻译 Guido 的解析器系列文章
Stars: ✭ 200 (+614.29%)
Mutual labels:  chinese-translation
Cngolib.com
Go 标准库中文文档
Stars: ✭ 235 (+739.29%)
Mutual labels:  chinese-translation
awesome-cybersecurity-blueteam-cn
网络安全 · 攻防对抗 · 蓝队清单,中文版
Stars: ✭ 494 (+1664.29%)
Mutual labels:  chinese-translation
Pyqt5 Chinese Tutorial
PyQt5中文教程
Stars: ✭ 2,574 (+9092.86%)
Mutual labels:  chinese-translation
Laravel Docs
Laravel 中文文档
Stars: ✭ 231 (+725%)
Mutual labels:  chinese-translation
vertx-guide-for-java-devs-chinese-translation
Chinese Translation of A-gentle-guide-to-asynchronous-programming-with-Eclipse-Vert.x-for-Java-developers
Stars: ✭ 20 (-28.57%)
Mutual labels:  chinese-translation
Docs Chinese
Fastify 中文文档
Stars: ✭ 183 (+553.57%)
Mutual labels:  chinese-translation
PHP-Chinese
PHP Chinese Conversion (中文繁簡轉換)
Stars: ✭ 37 (+32.14%)
Mutual labels:  chinese-translation
Awesome Nodejs Cn
nodejs优秀资源集
Stars: ✭ 230 (+721.43%)
Mutual labels:  chinese-translation
LANraragi cn
This repo is a fork of Difegue / LANraragi , those things i've done was to translate this repo into chinese ,and fix chrome browser js problem.
Stars: ✭ 147 (+425%)
Mutual labels:  chinese-translation
Nodejs Api Doc
📓Node.js API doc in Chinese
Stars: ✭ 210 (+650%)
Mutual labels:  chinese-translation
Akka Guide
🌴 A chinese guide of Akka, based on Java.
Stars: ✭ 217 (+675%)
Mutual labels:  chinese-translation
discussion
記錄有關繁化姬的議題或是內容
Stars: ✭ 33 (+17.86%)
Mutual labels:  chinese-translation
Chinese To Pinyin
一个将中文翻译成拼音的库
Stars: ✭ 199 (+610.71%)
Mutual labels:  chinese-translation
mml-book-chinese
mml-book-chinese《Mathematics For Machine Learning》机器学习中的数学 中文版
Stars: ✭ 113 (+303.57%)
Mutual labels:  chinese-translation
Elinux
嵌入式 Linux 知识库 (elinux.org) 中文翻译计划;本项目发起人发布了《360° 剖析 Linux ELF》视频课程,欢迎订阅:https://www.cctalk.com/m/group/88089283
Stars: ✭ 193 (+589.29%)
Mutual labels:  chinese-translation
ark-pixel-font
Open source Pan-CJK pixel font / 开源的泛中日韩像素字体
Stars: ✭ 1,767 (+6210.71%)
Mutual labels:  chinese-translation
HOCON-CN-Translation
Unofficial Simplified Chinese translation of HOCON.md in lightbend/config
Stars: ✭ 59 (+110.71%)
Mutual labels:  chinese-translation
A-Philosophy-of-Software-Design-zh
A Philosophy of Software Design 《软件设计的哲学》中文翻译
Stars: ✭ 172 (+514.29%)
Mutual labels:  chinese-translation
byte-of-python
《简明 Python 教程》V4.0c 2017 译本 /A Byte of Python 2017 Simplified Chinese Translation Edition
Stars: ✭ 604 (+2057.14%)
Mutual labels:  chinese-translation

English User See: README.EN.md

hanzi_to_pinyin

  • 获取汉字首字母
  • 获取汉字完整拼音
  • 把汉字转化为安全的 url

安装

ruby version <= 2.1.0

$ gem 'hanzi_to_pinyin', '1.0.0', require: 'hanzi_to_pinyin'

ruby version >=2.2.0

$ gem 'hanzi_to_pinyin', require: 'hanzi_to_pinyin'

使用

  # 获取首字母
  $ HanziToPinyin.hanzi_to_pinyin("中华人民共和国") #=> "zhrmghg"
  $ HanziToPinyin.hanzi_2_pinyin("中华人民共和国") #=> "zhrmghg"
  $ HanziToPinyin.hanzi_to_pinyin("喜欢Ruby") #=> "xhruby"
  $ HanziToPinyin.hanzi_2_pinyin("喜欢Ruby") #=> "xhruby"

  # 判断是否是汉字
  $ HanziToPinyin.is_hanzi?("你") #=> true
  $ HanziToPinyin.is_hanzi?("a") #=> false

  # 获取完整拼音
  # 多音字,分隔 字字之间;分隔,字母数字保留不变
  $ HanziToPinyin.hanzi_2_py("我们") #=> "wo;men"
  $ HanziToPinyin.hanzi_2_py("yyf") #=> "yyf"
  $ HanziToPinyin.hanzi_2_py("查理Smith") #=> "cha,zha;li;Smith"
  $ HanziToPinyin.hanzi_2_py("测试1") #=> "ce;shi;1"
  $ HanziToPinyin.hanzi_2_py("测_试") #=> "ce;_;shi"
  $ HanziToPinyin.hanzi_2_py("测-试") #=> "ce;-;shi"
  $ HanziToPinyin.hanzi_2_py(2) #=> "2"

  # 判断是否是数字
  $ HanziToPinyin.is_number?("1".ord) #=> true
  $ HanziToPinyin.is_number?("a".ord) #=> false

  # 判断是否是下划线
  $ HanziToPinyin.is_underline?("_".ord) #=> true
  $ HanziToPinyin.is_underline?("豆豆") #=> false
  
  # 判断是否是连接符
  $ HanziToPinyin.is_dash?("-".ord) #=> true

  # 汉字转化为安全的 url
  $ HanziToPinyin.hanzi_to_url("双11活动") #=> "shuang-1-1-huo-dong"
  $ HanziToPinyin.hanzi_to_url("双12活动&name=xxx") #=> "shuang-1-2-huo-dong-%26-n-a-m-e-%3D-x-x-x"

测试

$ rake spec

或者跑某个测试用例

$ rspec spec/hanzi_to_pinyin/hanzi_to_pinyin_spec.rb -l 21

ChangeLog

1.0.0

  • ruby 版本 < 2.1.0 使用

2.0.0

  • 升级 Rake 版本解决 Rake 安全漏洞问题
  CVE-2020-8130
  moderate severity
  Vulnerable versions: <= 12.3.2
  Patched version: 12.3.3
  There is an OS command injection vulnerability in Ruby Rake before 12.3.3 in Rake::FileList when supplying a filename that begins with the pipe character |.
  • 支持 Ruby >= 2.2.0

2.0.1

  • 修复"嗯"转化报错

版权

Copyright (c) 2011 wxianfeng. See LICENSE.txt for further details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].