From 4bc6eb9d41efbc2efb745391dae4375e4cba68a0 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Wed, 6 Oct 2021 13:15:49 -0700 Subject: [PATCH] Fix chinese transliteration when chinese characters are not followed by non-chinese characters --- translit/chinese.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/translit/chinese.go b/translit/chinese.go index 41d1170..763e37f 100644 --- a/translit/chinese.go +++ b/translit/chinese.go @@ -39,6 +39,14 @@ func (ct *ChineseTranslit) Transliterate(s string) string { 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 outBuf.String() }