mozillazg / go-pinyin

汉字转拼音
https://godoc.org/github.com/mozillazg/go-pinyin
MIT License
1.6k stars 194 forks source link

烦请作者添加英文原样输出支持,谢谢~ #51

Closed helloshaohua closed 3 years ago

helloshaohua commented 3 years ago
package converter

import "github.com/stretchr/testify/assert"

func (e *EncoderSuite) Test_ChineseToPinYinString() {
    grids := []struct {
        in       string
        sep      string
        expected string
    }{
        {in: "hello, 中国", sep: "", expected: "hello,zhongguo"},
    }

    for _, grid := range grids {
        actual := ChineseToPinYinString(grid.in, grid.sep)
        assert.Equal(e.T(), grid.expected, actual, "has error, want:%+v, but got: %+v, resource data value of the: %+v\n", grid.expected, actual, grid.in)
    }
}
mozillazg commented 3 years ago

@helloshaohua 可以通过 Fallback 参数实现。 https://pkg.go.dev/github.com/mozillazg/go-pinyin#Pinyin 中的 【Example (FallbackCustom1) 】

helloshaohua commented 3 years ago

好的,谢谢~