-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathLocalization.lua
165 lines (137 loc) · 6.33 KB
/
Localization.lua
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
local ADDON_NAME, Addon = ...
---------------------------------------------------------------------------------------------------
-- Imported functions and constants
---------------------------------------------------------------------------------------------------
-- Lua APIs
local format, pairs = format, pairs
-- ThreatPlates APIs
local TextCache = Addon.Cache.Texts
---------------------------------------------------------------------------------------------------
-- Default fonts by country
---------------------------------------------------------------------------------------------------
Addon.DEFAULT_FONT = "Cabin"
Addon.DEFAULT_SMALL_FONT = "Arial Narrow"
local client_locale = GetLocale()
local MAP_LOCALE_CONTENT = {
koKR = { -- Korrean
DefaultFont = "기본 글꼴", -- "2002"
DefaultSmallFont = "기본 글꼴", -- "2002"
},
zhCN = { -- Simplified Chinese
DefaultFont = "默认", -- "AR ZhongkaiGBK Medium"
DefaultSmallFont = "默认", -- "AR ZhongkaiGBK Medium"
},
zhTW = { -- Traditional Chinese
DefaultFont = "傷害數字", -- "AR Kaiti Medium B5"
DefaultSmallFont = "傷害數字", -- "AR Kaiti Medium B5"
},
ruRU = { -- Russian
DefaultFont = "Friz Quadrata TT", -- "FrizQuadrataCTT"
DefaultSmallFont = "Arial Narrow",
}
}
if MAP_LOCALE_CONTENT[client_locale] then
Addon.DEFAULT_FONT = MAP_LOCALE_CONTENT[client_locale].DefaultFont
Addon.DEFAULT_SMALL_FONT = MAP_LOCALE_CONTENT[client_locale].DefaultSmallFont
end
---------------------------------------------------------------------------------------------------
-- Totem names
---------------------------------------------------------------------------------------------------
local TOTEM_CREATURE_TYPE = {
enUS = "Totem",
deDE = "Totem",
esES = "Tótem",
esMX = "Totém",
frFR = "Totem",
itIT = "Totem",
ptBR = "Totem",
ruRU = "Тотем",
koKR = "토템",
zhCN = "图腾",
zhTW = "圖騰",
}
Addon.TotemCreatureType = TOTEM_CREATURE_TYPE[client_locale] or TOTEM_CREATURE_TYPE.enUS
---------------------------------------------------------------------------------------------------
-- Determine correct number units: Western or East Asian Nations (CJK)
---------------------------------------------------------------------------------------------------
local TruncateWestern = function(value)
local abs_value = (value >= 0 and value) or (-1 * value)
if abs_value >= 1e6 then
return format("%.1fm", value / 1e6)
elseif abs_value >= 1e4 then
return format("%.1fk", value / 1e3)
else
return format("%i", value)
end
end
-- TODO: NUMBER_ABBREVIATION_DATA - AbbreviateNumbers
local MAP_LOCALE_TO_UNIT_SYMBOL = {
koKR = { -- Korrean
Unit_1K = "천",
Unit_10K = "만",
Unit_1B = "억",
},
zhCN = { -- Simplified Chinese
Unit_1K = "千",
Unit_10K = "万",
Unit_1B = "亿",
},
zhTW = { -- Traditional Chinese
Unit_1K = "千",
Unit_10K = "萬",
Unit_1B = "億",
},
}
local TruncateEastAsian = TruncateWestern
if MAP_LOCALE_TO_UNIT_SYMBOL[client_locale] then
local Format_Unit_1K = "%.1f" .. MAP_LOCALE_TO_UNIT_SYMBOL[client_locale].Unit_1K
local Format_Unit_10K = "%.1f" .. MAP_LOCALE_TO_UNIT_SYMBOL[client_locale].Unit_10K
local Format_Unit_1B = "%.1f" .. MAP_LOCALE_TO_UNIT_SYMBOL[client_locale].Unit_1B
TruncateEastAsian = function(value)
local abs_value = (value > 0 and value) or (-1 * value)
if abs_value >= 1e8 then
return format(Format_Unit_1B, value / 1e8)
elseif abs_value >= 1e4 then
return format(Format_Unit_10K, value / 1e4)
elseif abs_value >= 1e3 then
return format(Format_Unit_1K, value / 1e3)
else
return format("%i", value)
end
end
end
Addon.Truncate = TruncateWestern
---------------------------------------------------------------------------------------------------
-- Transliteration
---------------------------------------------------------------------------------------------------
local TRANSLITERATE_CHARS = {
["А"] = "A", ["а"] = "a", ["Б"] = "B", ["б"] = "b", ["В"] = "V", ["в"] = "v", ["Г"] = "G", ["г"] = "g", ["Д"] = "D", ["д"] = "d", ["Е"] = "E",
["е"] = "e", ["Ё"] = "e", ["ё"] = "e", ["Ж"] = "Zh", ["ж"] = "zh", ["З"] = "Z", ["з"] = "z", ["И"] = "I", ["и"] = "i", ["Й"] = "Y", ["й"] = "y",
["К"] = "K", ["к"] = "k", ["Л"] = "L", ["л"] = "l", ["М"] = "M", ["м"] = "m", ["Н"] = "N", ["н"] = "n", ["О"] = "O", ["о"] = "o", ["П"] = "P",
["п"] = "p", ["Р"] = "R", ["р"] = "r", ["С"] = "S", ["с"] = "s", ["Т"] = "T", ["т"] = "t", ["У"] = "U", ["у"] = "u", ["Ф"] = "F", ["ф"] = "f",
["Х"] = "Kh", ["х"] = "kh", ["Ц"] = "Ts", ["ц"] = "ts", ["Ч"] = "Ch", ["ч"] = "ch", ["Ш"] = "Sh", ["ш"] = "sh", ["Щ"] = "Shch", ["щ"] = "shch",
["Ъ"] = "", ["ъ"] = "", ["Ы"] = "Y", ["ы"] = "y", ["Ь"] = "", ["ь"] = "", ["Э"] = "E", ["э"] = "e", ["Ю"] = "Yu", ["ю"] = "yu", ["Я"] = "Ya",
["я"] = "ya", -- [" "] = " ", -- Does not work, see comment below
}
function Addon.TransliterateCyrillicLetters(text)
if Addon.db.profile.Localization.TransliterateCyrillicLetters and text and text:len() > 1 then
local cache_entry = TextCache[text]
local transliterated_text = cache_entry.Transliteration
if not transliterated_text then
-- ! It seems to me that when using an array as 3rd argument, strings with uneven lenght are not processed correctly, depending on where the
-- ! double space is. If the double space starts at an even position, " " is not replaced with " " correctly using a table as 3rd argument.
transliterated_text = text:gsub(" ", " ") -- Deals with spaces so that sub can work with cyrillic guild names that have spaces
transliterated_text = transliterated_text:gsub("..", TRANSLITERATE_CHARS)
transliterated_text = transliterated_text:gsub(" ", " ") -- double space from above which gets replaced by single space
cache_entry.Transliteration = transliterated_text
end
return transliterated_text
end
return text
end
---------------------------------------------------------------------------------------------------
-- Update of settings
---------------------------------------------------------------------------------------------------
function Addon:UpdateConfigurationLocalization()
self.Truncate = (self.db.profile.text.LocalizedUnitSymbol and TruncateEastAsian) or TruncateWestern
end