-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In reference to previous commit.
- Loading branch information
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
``` |