Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rosbit/go-xpinyin
Translate Chinese hanzi to pinyin (拼音) by Golang, 汉字转拼音
https://github.com/rosbit/go-xpinyin
chinese-hanzi golang hanzi pinyin
Last synced: about 6 hours ago
JSON representation
Translate Chinese hanzi to pinyin (拼音) by Golang, 汉字转拼音
- Host: GitHub
- URL: https://github.com/rosbit/go-xpinyin
- Owner: rosbit
- License: mit
- Created: 2023-08-18T01:18:32.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2023-08-18T01:56:18.000Z (about 1 year ago)
- Last Synced: 2023-08-18T03:36:54.156Z (about 1 year ago)
- Topics: chinese-hanzi, golang, hanzi, pinyin
- Language: Go
- Homepage:
- Size: 124 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-xpinyin
Translate Chinese hanzi to pinyin (拼音) by Golang, 汉字转拼音.
Inspired by https://github.com/lxneng/xpinyin
## Usage
```go
package mainimport (
p "github.com/rosbit/go-xpinyin"
"fmt"
)func main() {
testGetPinyin("上海")
}func testGetPinyins(s string) {
fmt.Printf("GetPinyin(\"%s\")\n => %s\n", s, p.GetPinyin(s))
fmt.Printf("GetPinyin(\"%s\", WithToneMarks())\n => %s\n", s, p.GetPinyin(s, p.WithToneMarks()))
fmt.Printf("GetPinyin(\"%s\", WithToneNumbers())\n => %s\n", s, p.GetPinyin(s, p.WithToneNumbers()))
fmt.Printf("GetPinyin(\"%s\", WithSplitter(\"\"))\n => %s\n", s, p.GetPinyin(s, p.WithSplitter("")))
fmt.Printf("GetPinyin(\"%s\", WithSplitter(\" \"))\n => %s\n", s, p.GetPinyin(s, p.WithSplitter(" ")))
}
```## More
To see the detailed usage, run `go test`, the output is:
```
GetPinyin("上海")
=> shang-hai
GetPinyin("上海", WithToneMarks())
=> shàng-hǎi
GetPinyin("上海", WithToneNumbers())
=> shang4-hai3
GetPinyin("上海", WithSplitter(""))
=> shanghai
GetPinyin("上海", WithSplitter(" "))
=> shang hai
GetInitial('上')
=> S
GetInitials("上海")
=> S-H
GetInitials("上海", WithSplitter(""))
=> SH
GetInitials("上海", WithSplitter(" "))
=> S H
GetInitials("上海", WithRetroflex())
=> SH-H
GetPinyins("模型", WithToneMarks())
=> [mó-xíng mú-xíng]
GetPinyins("模样", WithToneMarks())
=> [mó-yáng mó-yàng mó-xiàng mú-yáng mú-yàng mú-xiàng]
PASS
ok github.com/rosbint/go-xpinyin 0.570s
```