Module:tg-Latn-Cyrl-translit
Jump to navigation
Jump to search
- The following documentation is generated by Module:documentation/functions/translit. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will transliterate Tajik language text per WT:TG TR.
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:tg-Latn-Cyrl-translit/testcases.
Functions
[edit]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 = {text}
local tt = {
["t"] = "т",
["r"] = "р",
["f"] = "ф",
["š"] = "ш",
["h"] = "ҳ",
["\'"] = "ъ",
["ʾ"] = "ъ",
["n"] = "н",
["p"] = "п",
["y"] = "й",
["l"] = "л",
["z"] = "з",
["e"] = "е",
["g"] = "г",
["b"] = "б",
["u"] = "у",
["ü"] = "ӯ",
["s"] = "с",
["x"] = "х",
["č"] = "ч",
["m"] = "м",
["o"] = "о",
["i"] = "и",
["ī"] = "ӣ",
["ž"] = "ж",
["k"] = "к",
["d"] = "д",
["v"] = "в",
["a"] = "а",
["j"] = "ҷ",
["q"] = "қ",
["ġ"] = "ғ",
--capital letters
-- fa-IPA doesnt support letter case.
-- these are here as a precaution
["T"] = "Т",
["R"] = "Р",
["F"] = "Ф",
["Š"] = "Ш",
["H"] = "Ҳ",
["N"] = "Н",
["P"] = "П",
["Y"] = "Й",
["L"] = "Л",
["Z"] = "З",
["E"] = "Е",
["G"] = "Г",
["B"] = "Б",
["U"] = "У",
["Ü"] = "Ӯ",
["S"] = "С",
["X"] = "Х",
["Č"] = "Ч",
["M"] = "М",
["O"] = "О",
["I"] = "И",
["Ī"] = "Ӣ",
["Ž"] = "Ж",
["K"] = "К",
["D"] = "Д",
["V"] = "В",
["A"] = "А",
["J"] = "Ҷ",
["Q"] = "Қ",
["Ġ"] = "Ғ",
-- ["ʾ"] = "Ъ" - this cant be uppercase in latin
["ye"] = "e",
["yi"] = "i",
["yī"] = "ī",
["yo"] = "ё",
["yu"] = "ю",
["ya"] = "я",
-- uppercase (fa-IPA doesnt support letter case, these are
-- precautionary)
["Ye"] = "Е",
["Yi"] = "I",
["Yī"] = "Ī",
["Yo"] = "Ё",
["Yu"] = "Ю",
["Ya"] = "Я",
}
local allchar = "AaBbVvGgĠġDdEeŽžZzIiĪīYyKkQqLlMmNnOoPpCcTtUuÜüFfXxHhČčJjŠšʾ"
local gsub = mw.ustring.gsub
function export.tr(text, lang, sc)
if type(text) == "table" then
options = {}
text, script = text.args[1], text.args[2]
end
if not sc then
sc = require("Module:languages").getByCode("tg"):findBestScript(text):getCode()
end
if sc ~= "Latn" then
if sc == "Arab" or sc == "fa-Arab"
then return require('Module:fa-cls-translit').tr(text)
end
else if sc == "Cyrl" or sc == "tg-Cyrl" then
return nil
end
end
-- if the input is Classical Persian, fix it
text = gsub(text, "ō", "ü")
text = gsub(text, "ē", "e")
text = gsub(text, "ū", "u")
text = gsub(text, "ī", "i")
text = gsub(text, "ā", "o")
--initial "e" forms
text = gsub(text, "([^" .. allchar .. "])" .. "e", "%1э")
text = gsub(text, "([^" .. allchar .. "])" .. "E", "%1Э")
--tajik orthography uses dashes but NOT the way fa-IPA does
--so they need to be removed
text = gsub(text, "%-i([^" .. allchar .. "])", "и%1")
text = gsub(text, "[Yy][eiīoua]", tt)
text = gsub(text, ".", tt)
return text
end
return export