flutterchina / lpinyin

Dart 汉字转拼音,Flutter, web, other
BSD 2-Clause "Simplified" License
365 stars 50 forks source link

Wrong pinyin when using Traditional characters #6

Open gustanas opened 3 years ago

gustanas commented 3 years ago

Example:

var testTrad = PinyinHelper.getPinyin('乾淨', format: PinyinFormat.WITH_TONE_MARK);
print(testTrad);
var testSimpl = PinyinHelper.getPinyin('干净', format: PinyinFormat.WITH_TONE_MARK);
print(testSimpl);

Output:

qián jìng
gān jìng
Sky24n commented 3 years ago
 List<String> traditionalDict= [ '乾=干'];
ChineseHelper.addChineseDict(traditionalDict);

var testTrad = PinyinHelper.getPinyin('乾淨', format: PinyinFormat.WITH_TONE_MARK);
print(testTrad);
gustanas commented 3 years ago

Thank you! It works already better!

But how about characters that have multiple pinyin? For example:

List<String> traditionalDict = ['乾=干'];
ChineseHelper.addChineseDict(traditionalDict);

var testTrad = PinyinHelper.getPinyin('乾燥', format: PinyinFormat.WITH_TONE_MARK);
var testTrad2 = PinyinHelper.getPinyin('乾坤', format: PinyinFormat.WITH_TONE_MARK);
print(testTrad);
print(testTrad2);

Output:

gān zào
gān kūn

Shoudn't it be qián kūn instead? https://translate.google.com/?sl=zh-CN&tl=zh-CN&text=%E4%B9%BE%E7%87%A5%0A%E4%B9%BE%E5%9D%A4&op=translate

Sky24n commented 3 years ago

This is a problem, maybe this solution is better.

List<String> multiDict = ['乾净=gān,jìng', '乾燥=gān,zào'];
PinyinHelper.addMultiPinyinDict(multiDict);

var testTrad = PinyinHelper.getPinyin('乾淨', format: PinyinFormat.WITH_TONE_MARK);
print(testTrad);
gustanas commented 3 years ago

Good suggestion, thank you for your help 🙏