-
Notifications
You must be signed in to change notification settings - Fork 0
/
romanize_belarusian.go
117 lines (107 loc) · 2.27 KB
/
romanize_belarusian.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package textutil
var belarusianConsonats = []rune{
'Б', 'В', 'Г', 'Д', 'Ж', 'З', 'Й', 'К', 'Л', 'М', 'Н',
'П', 'Р', 'С', 'Т', 'Ў', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Ь',
'б', 'в', 'г', 'д', 'ж', 'з', 'й', 'к', 'л', 'м', 'н',
'п', 'р', 'с', 'т', 'ў', 'ф', 'х', 'ц', 'ч', 'ш', 'ь',
}
func isBelarusianConsonat(r rune) bool {
for _, c := range belarusianConsonats {
if c == r {
return true
}
}
return false
}
func makeSoftBelarusianVowelRomanizer(hard, soft string) func(prev rune) string {
return func(prev rune) string {
if isBelarusianConsonat(prev) {
return soft
}
return hard
}
}
var tableBelarusian = map[rune]interface{}{
'А': 'A',
'а': 'a',
'Б': 'B',
'б': 'b',
'В': 'V',
'в': 'v',
'Г': 'H',
'г': 'h',
'Д': 'D',
'д': 'd',
'Е': makeSoftBelarusianVowelRomanizer("Je", "ie"),
'е': makeSoftBelarusianVowelRomanizer("je", "ie"),
'Ё': makeSoftBelarusianVowelRomanizer("Jo", "io"),
'ё': makeSoftBelarusianVowelRomanizer("jo", "io"),
'Ж': "Zh",
'ж': "zh",
'З': 'Z',
'з': 'z',
'І': 'I',
'і': 'i',
'Й': 'J',
'й': 'j',
'К': 'K',
'к': 'k',
'Л': 'L',
'л': 'l',
'М': 'M',
'м': 'm',
'Н': 'N',
'н': 'n',
'О': 'O',
'о': 'o',
'П': 'P',
'п': 'p',
'Р': 'R',
'р': 'r',
'С': 'S',
'с': 's',
'Т': 'T',
'т': 't',
'У': 'U',
'у': 'u',
'Ў': 'U',
'ў': 'u',
'Ф': 'F',
'ф': 'f',
'Х': "Ch",
'х': "ch",
'Ц': 'C',
'ц': 'c',
'Ч': "Ch",
'ч': "ch",
'Ш': "Sh",
'ш': "sh",
'’': nil,
'\'': nil,
'Ы': 'Y',
'ы': 'y',
'Ь': nil,
'ь': nil,
'Э': 'E',
'э': 'e',
'Ю': makeSoftBelarusianVowelRomanizer("Ju", "iu"),
'ю': makeSoftBelarusianVowelRomanizer("ju", "iu"),
'Я': makeSoftBelarusianVowelRomanizer("Ja", "ia"),
'я': makeSoftBelarusianVowelRomanizer("ja", "ia"),
}
var tableBelarusianV2 map[rune]any = map[rune]any{}
func init() {
for k, v := range tableBelarusian {
tableBelarusianV2[k] = v
}
tableBelarusianV2['Х'] = "Kh"
tableBelarusianV2['х'] = "kh"
tableBelarusianV2['Ь'] = "'"
tableBelarusianV2['ь'] = "'"
}
func RomanizeBelarusian(s string) string {
return romanize(s, tableBelarusian)
}
func RomanizeBelarusianV2(s string) string {
return romanize(s, tableBelarusianV2)
}