Skip to content

Commit a236e31

Browse files
committed
Added support for cyrillic letters transliteration in Name status (ticket #930)
1 parent cc7f17c commit a236e31

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

.pkgmeta-classic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ignore:
2929
- modules/StatusHealAbsorbs.lua
3030
- modules/StatusSummon.lua
3131
- modules/StatusPhased.lua
32+
- modules/StatusStagger.lua
3233
- RaidDebuffsOptions/RaidDebuffsBfA.lua
3334
- RaidDebuffsOptions/RaidDebuffsLegion.lua
3435
- RaidDebuffsOptions/RaidDebuffsShadowlands.lua

GridUtils.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ do
8484
end
8585
end
8686

87+
-- Transliterate texts, cyrilic to latin conversion
88+
do
89+
local gsub = string.gsub
90+
local Cyr2Lat = {
91+
["А"] = "A", ["а"] = "a", ["Б"] = "B", ["б"] = "b", ["В"] = "V", ["в"] = "v", ["Г"] = "G", ["г"] = "g", ["Д"] = "D", ["д"] = "d", ["Е"] = "E",
92+
["е"] = "e", ["Ё"] = "e", ["ё"] = "e", ["Ж"] = "Zh", ["ж"] = "zh", ["З"] = "Z", ["з"] = "z", ["И"] = "I", ["и"] = "i", ["Й"] = "Y", ["й"] = "y",
93+
["К"] = "K", ["к"] = "k", ["Л"] = "L", ["л"] = "l", ["М"] = "M", ["м"] = "m", ["Н"] = "N", ["н"] = "n", ["О"] = "O", ["о"] = "o", ["П"] = "P",
94+
["п"] = "p", ["Р"] = "R", ["р"] = "r", ["С"] = "S", ["с"] = "s", ["Т"] = "T", ["т"] = "t", ["У"] = "U", ["у"] = "u", ["Ф"] = "F", ["ф"] = "f",
95+
["Х"] = "Kh", ["х"] = "kh", ["Ц"] = "Ts", ["ц"] = "ts", ["Ч"] = "Ch", ["ч"] = "ch", ["Ш"] = "Sh", ["ш"] = "sh", ["Щ"] = "Shch", ["щ"] = "shch",
96+
["Ъ"] = "", ["ъ"] = "", ["Ы"] = "Y", ["ы"] = "y", ["Ь"] = "", ["ь"] = "", ["Э"] = "E", ["э"] = "e", ["Ю"] = "Yu", ["ю"] = "yu", ["Я"] = "Ya",
97+
["я"] = "ya"
98+
}
99+
function Grid2.strCyr2Lat(str)
100+
return gsub(str, "..", Cyr2Lat)
101+
end
102+
end
103+
87104
-- Table Deep Copy used by GridDefaults.lua
88105
function Grid2.CopyTable(src, dst)
89106
if type(dst)~="table" then dst = {} end

Options/modules.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<Script file="modules\statuses\StatusThreat.lua"/>
3636
<Script file="modules\statuses\StatusCombat.lua"/>
3737
<Script file="modules\statuses\StatusMisc.lua"/>
38+
<Script file="modules\statuses\StatusName.lua"/>
3839

3940
<Script file="modules\indicators\Indicator.lua"/>
4041
<Script file="modules\indicators\IndicatorAlpha.lua"/>

Options/modules/statuses/StatusMisc.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
local L = Grid2Options.L
44

5-
Grid2Options:RegisterStatusOptions("name", "hidden")
6-
75
Grid2Options:RegisterStatusOptions("afk", "misc", nil, {
86
titleIcon = "Interface\\ICONS\\Spell_nature_sleep"
97
})
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
local L = Grid2Options.L
2+
3+
Grid2Options:RegisterStatusOptions("name", "misc", function(self, status, options, optionParams)
4+
options.transliterate = {
5+
type = "toggle",
6+
order = 10,
7+
width = "full",
8+
name = L["Transliterate Names"],
9+
desc = L["Convert cyrillic letters to latin alphabet."],
10+
get = function () return status.dbx.enableTransliterate end,
11+
set = function (_, v)
12+
status.dbx.enableTransliterate = v or nil
13+
status:UpdateDB()
14+
status:UpdateAllUnits()
15+
end,
16+
}
17+
end )

modules/StatusName.lua

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
local Name = Grid2.statusPrototype:new("name")
22

3-
local UnitName = UnitName
3+
local UnitName = UnitName
4+
local strCyr2Lat = Grid2.strCyr2Lat
45

56
Name.IsActive = Grid2.statusLibrary.IsActive
67

8+
local defaultName
9+
10+
local function GetText1(self, unit)
11+
return UnitName(unit) or (defaultName==1 and unit) or defaultName or ''
12+
end
13+
14+
local function GetText2(self, unit)
15+
local name = UnitName(unit)
16+
return (name and strCyr2Lat(name)) or (defaultName==1 and unit) or defaultName or ''
17+
end
18+
719
function Name:UNIT_NAME_UPDATE(_, unit)
820
self:UpdateIndicators(unit)
921
end
@@ -16,17 +28,18 @@ function Name:OnDisable()
1628
self:UnregisterEvent("UNIT_NAME_UPDATE")
1729
end
1830

19-
function Name:GetText(unit)
20-
return UnitName(unit)
21-
end
22-
2331
function Name:GetTooltip(unit,tip)
2432
tip:SetUnit(unit)
2533
end
2634

35+
function Name:UpdateDB()
36+
defaultName = self.dbx.defaultName
37+
Name.GetText = self.dbx.enableTransliterate and GetText2 or GetText1
38+
end
39+
2740
local function Create(baseKey, dbx)
2841
Grid2:RegisterStatus(Name, {"text","tooltip"}, baseKey, dbx)
29-
42+
Name:UpdateDB()
3043
return Name
3144
end
3245

0 commit comments

Comments
 (0)