https://github.com/mozillazg/go-pinyin.git
evan.hong fda20c9f20 init | 3 years ago | |
---|---|---|
.github | 3 years ago | |
_tools | 3 years ago | |
cmd | 3 years ago | |
.editorconfig | 3 years ago | |
.gitignore | 3 years ago | |
.gitmodules | 3 years ago | |
.travis.yml | 3 years ago | |
CHANGELOG.md | 3 years ago | |
LICENSE | 3 years ago | |
Makefile | 3 years ago | |
README.md | 3 years ago | |
benchmark_test.go | 3 years ago | |
doc.go | 3 years ago | |
example_test.go | 3 years ago | |
go.mod | 3 years ago | |
phonetic_symbol.go | 3 years ago | |
pinyin.go | 3 years ago | |
pinyin_dict.go | 3 years ago | |
pinyin_test.go | 3 years ago |
汉语拼音转换工具 Go 版。
go get -u github.com/mozillazg/go-pinyin
install CLI tool:
go get -u github.com/mozillazg/go-pinyin/cmd/pinyin
$ pinyin 中国人
zhōng guó rén
API documentation can be found here: https://godoc.org/github.com/mozillazg/go-pinyin
package main
import (
"fmt"
"github.com/mozillazg/go-pinyin"
)
func main() {
hans := "中国人"
// 默认
a := pinyin.NewArgs()
fmt.Println(pinyin.Pinyin(hans, a))
// [[zhong] [guo] [ren]]
// 包含声调
a.Style = pinyin.Tone
fmt.Println(pinyin.Pinyin(hans, a))
// [[zhōng] [guó] [rén]]
// 声调用数字表示
a.Style = pinyin.Tone2
fmt.Println(pinyin.Pinyin(hans, a))
// [[zho1ng] [guo2] [re2n]]
// 开启多音字模式
a = pinyin.NewArgs()
a.Heteronym = true
fmt.Println(pinyin.Pinyin(hans, a))
// [[zhong zhong] [guo] [ren]]
a.Style = pinyin.Tone2
fmt.Println(pinyin.Pinyin(hans, a))
// [[zho1ng zho4ng] [guo2] [re2n]]
fmt.Println(pinyin.LazyPinyin(hans, pinyin.NewArgs()))
// [zhong guo ren]
fmt.Println(pinyin.Convert(hans, nil))
// [[zhong] [guo] [ren]]
fmt.Println(pinyin.LazyConvert(hans, nil))
// [zhong guo ren]
}
注意:
Fallback
参数的值来自定义如何处理没有拼音的字符,
详见 示例)。FirstLetter
( 详细信息 )。Under the MIT License.