Add and fix comments, fix transliteration maps so only first character is capitalized

This commit is contained in:
Arsen Musayelyan 2021-10-06 13:26:16 -07:00
parent 4bc6eb9d41
commit c23201e18c
3 changed files with 15 additions and 7 deletions

View File

@ -124,16 +124,23 @@ var armenianMap = []string{
func (at *ArmenianTranslit) Init() { func (at *ArmenianTranslit) Init() {
if !at.initComplete { if !at.initComplete {
// Copy map as original will be changed
lower := armenianMap lower := armenianMap
// For every value in copied map
for i, val := range lower { for i, val := range lower {
// If index is odd, skip
if i%2 == 1 { if i%2 == 1 {
continue continue
} }
// Capitalize first letter
capital := strings.Title(val) capital := strings.Title(val)
// If capital is not the same as lowercase
if capital != val { if capital != val {
// Add capital to map
armenianMap = append(armenianMap, capital, strings.Title(armenianMap[i+1])) armenianMap = append(armenianMap, capital, strings.Title(armenianMap[i+1]))
} }
} }
// Set init complete to true so it is not run again
at.initComplete = true at.initComplete = true
} }
} }

View File

@ -39,6 +39,7 @@ func (ct *ChineseTranslit) Transliterate(s string) string {
outBuf.WriteRune(char) outBuf.WriteRune(char)
} }
} }
// If buffer contains characters
if tmpBuf.Len() > 0 { if tmpBuf.Len() > 0 {
// Convert to pinyin (without tones) // Convert to pinyin (without tones)
out := pinyin.LazyConvert(tmpBuf.String(), nil) out := pinyin.LazyConvert(tmpBuf.String(), nil)

View File

@ -41,7 +41,7 @@ type Transliterator interface {
} }
// Map implements Transliterator using a slice where // Map implements Transliterator using a slice where
// every odd element is a key and every even one is a value // every even element is a key and every odd one is a value
// which replaces the key. // which replaces the key.
type Map []string type Map []string
@ -155,7 +155,7 @@ var Transliterators = map[string]Transliterator{
"Ζ", "Z", "Ζ", "Z",
"Η", "I", "Η", "I",
"Ή", "I", "Ή", "I",
"Θ", "TH", "Θ", "Th",
"Ι", "I", "Ι", "I",
"Ί", "I", "Ί", "I",
"Ϊ", "I", "Ϊ", "I",
@ -163,7 +163,7 @@ var Transliterators = map[string]Transliterator{
"Λ", "L", "Λ", "L",
"Μ", "M", "Μ", "M",
"Ν", "N", "Ν", "N",
"Ξ", "KS", "Ξ", "Ks",
"Ο", "O", "Ο", "O",
"Ό", "O", "Ό", "O",
"Π", "P", "Π", "P",
@ -174,8 +174,8 @@ var Transliterators = map[string]Transliterator{
"Ύ", "Y", "Ύ", "Y",
"Ϋ", "Y", "Ϋ", "Y",
"Φ", "F", "Φ", "F",
"Χ", "CH", "Χ", "Ch",
"Ψ", "PS", "Ψ", "Ps",
"Ω", "O", "Ω", "O",
"Ώ", "O", "Ώ", "O",
}, },
@ -188,8 +188,8 @@ var Transliterators = map[string]Transliterator{
"є", "je", "є", "je",
"і", "i", "і", "i",
"ї", "ji", "ї", "ji",
"Ґ", "GH", "Ґ", "Gh",
"Є", "JE", "Є", "Je",
"І", "I", "І", "I",
"Ї", "JI", "Ї", "JI",
}, },