Skip to content

Commit

Permalink
Added LibTranslit-1.0
Browse files Browse the repository at this point in the history
In reference to previous commit.
  • Loading branch information
Tercioo committed Oct 27, 2019
1 parent b700d87 commit 5e05d6b
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ locales/Details-esMX.lua
locales/Details-esES.lua
locales/Details-enUS.lua
locales/Details-deDE.lua
Libs/LibTranslit/.pkgmeta
113 changes: 113 additions & 0 deletions Libs/LibTranslit/LibTranslit-1.0.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
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
13 changes: 13 additions & 0 deletions Libs/LibTranslit/LibTranslit-1.0.toc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Interface: 80200
## Title: Lib: Translit
## Notes: Transliterate string
## Author: Vardex
## X-Category: Library
## X-License: BSD
## Version: @project-version@
## DefaultState: Enabled
## LoadOnDemand: 0

LibStub\LibStub.lua

LibTranslit-1.0.xml
4 changes: 4 additions & 0 deletions Libs/LibTranslit/LibTranslit-1.0.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
<Script file = "LibTranslit-1.0.lua"/>
</Ui>
10 changes: 10 additions & 0 deletions Libs/LibTranslit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# LibTranslit

Transliterate string

## Usage

```Lua
local LibTranslit = LibStub("LibTranslit-1.0")
local transliteratedString = LibTranslit:Transliterate(string[, mark])
```

0 comments on commit 5e05d6b

Please sign in to comment.