Fix chinese transliteration when chinese characters are not followed by non-chinese characters

This commit is contained in:
Elara 2021-10-06 13:15:49 -07:00
parent 2a59e74a2c
commit 4bc6eb9d41

View File

@ -39,6 +39,14 @@ func (ct *ChineseTranslit) Transliterate(s string) string {
outBuf.WriteRune(char) outBuf.WriteRune(char)
} }
} }
if tmpBuf.Len() > 0 {
// Convert to pinyin (without tones)
out := pinyin.LazyConvert(tmpBuf.String(), nil)
// Write space-separated string to output
outBuf.WriteString(strings.Join(out, " "))
// Reset temporary buffer
tmpBuf.Reset()
}
// Return output string // Return output string
return outBuf.String() return outBuf.String()
} }