Browse Source

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

pull/12/head
Arsen Musayelyan 8 months ago
parent
commit
c23201e18c
  1. 7
      translit/armenian.go
  2. 1
      translit/chinese.go
  3. 14
      translit/translit.go

7
translit/armenian.go

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

1
translit/chinese.go

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

14
translit/translit.go

@ -41,7 +41,7 @@ type Transliterator interface {
}
// 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.
type Map []string
@ -155,7 +155,7 @@ var Transliterators = map[string]Transliterator{
"Ζ", "Z",
"Η", "I",
"Ή", "I",
"Θ", "TH",
"Θ", "Th",
"Ι", "I",
"Ί", "I",
"Ϊ", "I",
@ -163,7 +163,7 @@ var Transliterators = map[string]Transliterator{
"Λ", "L",
"Μ", "M",
"Ν", "N",
"Ξ", "KS",
"Ξ", "Ks",
"Ο", "O",
"Ό", "O",
"Π", "P",
@ -174,8 +174,8 @@ var Transliterators = map[string]Transliterator{
"Ύ", "Y",
"Ϋ", "Y",
"Φ", "F",
"Χ", "CH",
"Ψ", "PS",
"Χ", "Ch",
"Ψ", "Ps",
"Ω", "O",
"Ώ", "O",
},
@ -188,8 +188,8 @@ var Transliterators = map[string]Transliterator{
"є", "je",
"і", "i",
"ї", "ji",
"Ґ", "GH",
"Є", "JE",
"Ґ", "Gh",
"Є", "Je",
"І", "I",
"Ї", "JI",
},

Loading…
Cancel
Save