From 5e05d6b824214e15e4ff3ddbb12526e510c67b01 Mon Sep 17 00:00:00 2001 From: Tercio Jose Date: Sun, 27 Oct 2019 18:13:54 -0300 Subject: [PATCH] Added LibTranslit-1.0 In reference to previous commit. --- .gitignore | 1 + Libs/LibTranslit/LibTranslit-1.0.lua | 113 +++++++++++++++++++++++++++ Libs/LibTranslit/LibTranslit-1.0.toc | 13 +++ Libs/LibTranslit/LibTranslit-1.0.xml | 4 + Libs/LibTranslit/README.md | 10 +++ 5 files changed, 141 insertions(+) create mode 100644 Libs/LibTranslit/LibTranslit-1.0.lua create mode 100644 Libs/LibTranslit/LibTranslit-1.0.toc create mode 100644 Libs/LibTranslit/LibTranslit-1.0.xml create mode 100644 Libs/LibTranslit/README.md diff --git a/.gitignore b/.gitignore index 5476b429c..3f08f198a 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ locales/Details-esMX.lua locales/Details-esES.lua locales/Details-enUS.lua locales/Details-deDE.lua +Libs/LibTranslit/.pkgmeta diff --git a/Libs/LibTranslit/LibTranslit-1.0.lua b/Libs/LibTranslit/LibTranslit-1.0.lua new file mode 100644 index 000000000..774d7b179 --- /dev/null +++ b/Libs/LibTranslit/LibTranslit-1.0.lua @@ -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 diff --git a/Libs/LibTranslit/LibTranslit-1.0.toc b/Libs/LibTranslit/LibTranslit-1.0.toc new file mode 100644 index 000000000..3685e9b80 --- /dev/null +++ b/Libs/LibTranslit/LibTranslit-1.0.toc @@ -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 diff --git a/Libs/LibTranslit/LibTranslit-1.0.xml b/Libs/LibTranslit/LibTranslit-1.0.xml new file mode 100644 index 000000000..8abefcebb --- /dev/null +++ b/Libs/LibTranslit/LibTranslit-1.0.xml @@ -0,0 +1,4 @@ + +