Module:ug-translit
Jump to navigation
Jump to search
- The following documentation is located at Module:ug-translit/documentation. [edit] Categories were auto-generated by Module:module categorization. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will transliterate Uyghur language text.
The module should preferably not be called directly from templates or other modules.
To use it from a template, use {{xlit}}
.
Within a module, use Module:languages#Language:transliterate.
For testcases, see Module:ug-translit/testcases.
Functions
tr(text, lang, sc)
- Transliterates a given piece of
text
written in the script specified by the codesc
, and language specified by the codelang
. - When the transliteration fails, returns
nil
.
local export = {}
local data = {}
data["ug-Arab"] = {
-- consonants
["م"] = "m", ["ن"] = "n", ["د"] = "d", ["ت"] = "t",
["ب"] = "b", ["پ"] = "p", ["ف"] = "f", ["ق"] = "q",
["ك"] = "k", ["ڭ"] = "ng", ["گ"] = "g", ["غ"] = "gh",
["ھ"] = "h", ["خ"] = "x", ["چ"] = "ch",
["ج"] = "j", ["ژ"] = "zh", ["ز"] = "z", ["س"] = "s",
["ش"] = "sh", ["ر"] = "r", ["ل"] = "l", ["ئ"] = "'",
["ي"] = "y", ["ۋ"] = "w",
-- vowels
["ا"] = "a", ["ە"] = "e", ["ې"] = "ë", ["ى"] = "i",
["و"] = "o", ["ۆ"] = "ö", ["ۇ"] = "u", ["ۈ"] = "ü",
-- punctuation
["؟"]="?",
["،"]=",",
["؛"]=";",
["ـ"]="-"
}
data["Arab"] = data["ug-Arab"]
data["Cyrl"] = {
["А"] = "A", ["Б"] = "B", ["В"] = "W", ["Г"] = "G", ["Ғ"] = "Gh", ["Д"] = "D", ["Е"] = "Ë", ["Ә"] = "E", ["Ж"] = "Zh", ["Җ"] = "J",
["З"] = "Z", ["И"] = "I", ["Й"] = "Y", ["К"] = "K", ["Қ"] = "Q", ["Л"] = "L", ["М"] = "M", ["Н"] = "N", ["Ң"] = "Ng", ["О"] = "O",
["Ө"] = "Ö", ["П"] = "P", ["Р"] = "R", ["С"] = "S", ["Т"] = "T", ["У"] = "U", ["Ү"] = "Ü", ["Ф"] = "F", ["Х"] = "X", ["Һ"] = "H",
["Ч"] = "Ch", ["Ш"] = "Sh", ["Ю"] = "Yu", ["Я"] = "Ya",
["Э"] = "É",
["а"] = "a", ["б"] = "b", ["в"] = "w", ["г"] = "g", ["ғ"] = "gh", ["д"] = "d", ["е"] = "ë", ["ә"] = "e", ["ж"] = "zh", ["җ"] = "j",
["з"] = "z", ["и"] = "i", ["й"] = "y", ["к"] = "k", ["қ"] = "q", ["л"] = "l", ["м"] = "m", ["н"] = "n", ["ң"] = "ng", ["о"] = "o",
["ө"] = "ö", ["п"] = "p", ["р"] = "r", ["с"] = "s", ["т"] = "t", ["у"] = "u", ["ү"] = "ü", ["ф"] = "f", ["х"] = "x", ["һ"] = "h",
["ч"] = "ch", ["ш"] = "sh", ["ю"] = "yu", ["я"] = "ya",
["э"] = "é",
}
function export.tr(text, lang, sc)
if not sc then
sc = require("Module:languages").getByCode(lang):findBestScript(text):getCode()
end
if sc ~= "ug-Arab" and sc ~= "Arab" and sc ~= "Cyrl" then
return nil
end
-- remove initial hamza
text = mw.ustring.gsub(text, "^\216\166(.)", "%1")
text = mw.ustring.gsub(text, "%s\216\166(.)", " %1")
-- add apostrophe in some cases
text = mw.ustring.gsub(text, "([اەوۇۆۈېىаәоуөүеиАӘОУӨҮЕИ])([ڭң])([اەوۇۆۈېىаәоуөүеи])", "%1'%2%3") -- V'ngV
text = mw.ustring.gsub(text, "([نн])([گغгғ])", "%1'%2") -- n'g & n'gh
text = mw.ustring.gsub(text, "([ڭң])([ھһ])", "%1'%2") -- ng'h
text = mw.ustring.gsub(text, "([زз])([ھһ])", "%1'%2") -- z'h
text = mw.ustring.gsub(text, '.', data[sc])
return text
end
return export