Commit 9515123e authored by Vardex's avatar Vardex

Added support for transliteration

parent 3447354a
local MAJOR_VERSION = "LibTranslit-1.0"
local MINOR_VERSION = 3
if not LibStub then
error(MAJOR_VERSION .. " requires LibStub.")
end
local lib = LibStub:NewLibrary(MAJOR_VERSION, MINOR_VERSION)
if not lib then
return
end
local CyrToLat = {
["А"] = "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"
}
function lib:Transliterate(str, mark)
if not str then
return ""
end
local mark = mark or ""
local tstr = ""
local marked = false
local i = 1
while i <= string.len(str) do
local c = str:sub(i, i)
local b = string.byte(c)
if b == 208 or b == 209 then
if marked == false then
tstr = tstr .. mark
marked = true
end
c = str:sub(i + 1, i + 1)
tstr = tstr .. (CyrToLat[string.char(b, string.byte(c))] or string.char(b, string.byte(c)))
i = i + 2
else
if c == " " or c == "-" then
marked = false
end
tstr = tstr .. c
i = i + 1
end
end
return tstr
end
......@@ -26,4 +26,5 @@
<Include file="LibCompress\lib.xml"/>
<Include file="LibBase64-1.0\lib.xml"/>
<Script file="LibAnim\LibAnim.lua"/>
<Script file="LibTranslit-1.0\LibTranslit-1.0.lua"/>
</Ui>
......@@ -2,6 +2,8 @@ local E, L, V, P, G = unpack(select(2, ...)); --Import: Engine, Locales, Private
local _, ns = ...
local ElvUF = ns.oUF
assert(ElvUF, "ElvUI was unable to locate oUF.")
local Translit = E.Libs.Translit
local translitMark = "!"
--Lua functions
local _G = _G
......@@ -674,6 +676,30 @@ ElvUF.Tags.Methods['name:long:status'] = function(unit)
end
end
ElvUF.Tags.Events['name:veryshort:translit'] = 'UNIT_NAME_UPDATE'
ElvUF.Tags.Methods['name:veryshort:translit'] = function(unit)
local name = Translit:Transliterate(UnitName(unit), translitMark)
return name ~= nil and E:ShortenString(name, 5) or nil
end
ElvUF.Tags.Events['name:short:translit'] = 'UNIT_NAME_UPDATE'
ElvUF.Tags.Methods['name:short:translit'] = function(unit)
local name = Translit:Transliterate(UnitName(unit), translitMark)
return name ~= nil and E:ShortenString(name, 10) or nil
end
ElvUF.Tags.Events['name:medium:translit'] = 'UNIT_NAME_UPDATE'
ElvUF.Tags.Methods['name:medium:translit'] = function(unit)
local name = Translit:Transliterate(UnitName(unit), translitMark)
return name ~= nil and E:ShortenString(name, 15) or nil
end
ElvUF.Tags.Events['name:long:translit'] = 'UNIT_NAME_UPDATE'
ElvUF.Tags.Methods['name:long:translit'] = function(unit)
local name = Translit:Transliterate(UnitName(unit), translitMark)
return name ~= nil and E:ShortenString(name, 20) or nil
end
ElvUF.Tags.Events['realm'] = 'UNIT_NAME_UPDATE'
ElvUF.Tags.Methods['realm'] = function(unit)
local _, realm = UnitName(unit)
......@@ -698,6 +724,31 @@ ElvUF.Tags.Methods['realm:dash'] = function(unit)
return realm
end
ElvUF.Tags.Events['realm:translit'] = 'UNIT_NAME_UPDATE'
ElvUF.Tags.Methods['realm:translit'] = function(unit)
local _, realm = Translit:Transliterate(UnitName(unit), translitMark)
if realm and realm ~= "" then
return realm
else
return nil
end
end
ElvUF.Tags.Events['realm:dash:translit'] = 'UNIT_NAME_UPDATE'
ElvUF.Tags.Methods['realm:dash:translit'] = function(unit)
local _, realm = Translit:Transliterate(UnitName(unit), translitMark)
if realm and (realm ~= "" and realm ~= E.myrealm) then
realm = format("-%s", realm)
elseif realm == "" then
realm = nil
end
return realm
end
ElvUF.Tags.Events['threat:percent'] = 'UNIT_THREAT_LIST_UPDATE GROUP_ROSTER_UPDATE'
ElvUF.Tags.Methods['threat:percent'] = function(unit)
local _, _, percent = UnitDetailedThreatSituation('player', unit)
......@@ -1140,6 +1191,20 @@ ElvUF.Tags.Methods['guild:brackets'] = function(unit)
return guildName and format("<%s>", guildName) or nil
end
ElvUF.Tags.Events['guild:translit'] = 'UNIT_NAME_UPDATE PLAYER_GUILD_UPDATE'
ElvUF.Tags.Methods['guild:translit'] = function(unit)
if (UnitIsPlayer(unit)) then
return Translit:Transliterate(GetGuildInfo(unit), translitMark) or nil
end
end
ElvUF.Tags.Events['guild:brackets:translit'] = 'PLAYER_GUILD_UPDATE'
ElvUF.Tags.Methods['guild:brackets:translit'] = function(unit)
local guildName = Translit:Transliterate(GetGuildInfo(unit), translitMark)
return guildName and format("<%s>", guildName) or nil
end
ElvUF.Tags.Events['target:veryshort'] = 'UNIT_TARGET'
ElvUF.Tags.Methods['target:veryshort'] = function(unit)
local targetName = UnitName(unit.."target")
......@@ -1169,3 +1234,33 @@ ElvUF.Tags.Methods['target'] = function(unit)
local targetName = UnitName(unit.."target")
return targetName or nil
end
ElvUF.Tags.Events['target:veryshort:translit'] = 'UNIT_TARGET'
ElvUF.Tags.Methods['target:veryshort:translit'] = function(unit)
local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
return targetName ~= nil and E:ShortenString(targetName, 5) or nil
end
ElvUF.Tags.Events['target:short:translit'] = 'UNIT_TARGET'
ElvUF.Tags.Methods['target:short:translit'] = function(unit)
local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
return targetName ~= nil and E:ShortenString(targetName, 10) or nil
end
ElvUF.Tags.Events['target:medium:translit'] = 'UNIT_TARGET'
ElvUF.Tags.Methods['target:medium:translit'] = function(unit)
local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
return targetName ~= nil and E:ShortenString(targetName, 15) or nil
end
ElvUF.Tags.Events['target:long:translit'] = 'UNIT_TARGET'
ElvUF.Tags.Methods['target:long:translit'] = function(unit)
local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
return targetName ~= nil and E:ShortenString(targetName, 20) or nil
end
ElvUF.Tags.Events['target:translit'] = 'UNIT_TARGET'
ElvUF.Tags.Methods['target:translit'] = function(unit)
local targetName = Translit:Transliterate(UnitName(unit.."target"), translitMark)
return targetName or nil
end
......@@ -98,7 +98,8 @@ AddOn.Libs = {
ItemSearch = _G.LibStub('LibItemSearch-1.2-ElvUI'),
Compress = _G.LibStub('LibCompress'),
Base64 = _G.LibStub('LibBase64-1.0-ElvUI'),
Masque = _G.LibStub('Masque', true)
Masque = _G.LibStub('Masque', true),
Translit = _G.LibStub('LibTranslit-1.0')
} -- added on ElvUI_Config load: AceGUI, AceConfig, AceConfigDialog, AceConfigRegistry, AceDBOptions
-- backwards compatible for plugins
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment