Module:sjt-translit
Appearance
- The following documentation is generated by Module:documentation/functions/translit. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will transliterate Ter Sami 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:sjt-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 = {}
local u = mw.ustring.char
local macron = u(0x0304)
local tt = {
["А"]='A', ["а"]='a',
["Ӓ"]="’a", ["ӓ"]="’a",
["Б"]='B', ["б"]='b',
["В"]='V', ["в"]='v',
["Г"]='G', ["г"]='g',
["Д"]='D', ["д"]='d',
["Е"]='Je', ["е"]='je',
["Ё"]="Jo", ["ё"]="jo",
["Ж"]='Ž', ["ж"]='ž',
["З"]='Z', ["з"]='z',
["Һ"]="H", ["һ"]="h", ["ʼ"]="h",
["И"]='I', ["и"]='i',
["Ӣ"]="Ī", ["ӣ"]="ī",
["Й"]="J", ["й"]="j",
["Ј"]="J̥", ["ј"]="j̥", ["Ҋ"]="J̥", ["ҋ"]="j̥",
["К"]='K', ["к"]='k',
["Л"]='L', ["л"]='l',
["Ӆ"]='L̥', ["ӆ"]='l̥',
["М"]='M', ["м"]='m',
["Ӎ"]="M̥", ["ӎ"]="m̥",
["Н"]='N', ["н"]='n',
["Ӊ"]="N̥", ["ӊ"]="n̥",
["Ӈ"]="Ŋ", ["ӈ"]="ŋ",
["О"]='O', ["о"]='o',
["П"]='P', ["п"]='p',
["Р"]='R', ["р"]='r',
["Ҏ"]="R̥", ["ҏ"]="r̥",
["С"]='S', ["с"]='s',
["Т"]='T', ["т"]='t',
["У"]='U', ["у"]='u',
["Ӯ"]="Ū", ["ӯ"]="ū",
["Ф"]='F', ["ф"]='f',
["Х"]='H', ["х"]='x',
["Ц"]='C', ["ц"]='c',
["Ч"]='Č', ["ч"]='č',
["Ш"]='Š', ["ш"]='š',
["Щ"]="Šč", ["щ"]="šč",
["Ы"]="Ï", ["ы"]="ï",
["Ъ"]="", ["ъ"]="",
["Ь"]="ʼ", ["ь"]="ʼ", ["Ҍ"]= "ʼ", ["ҍ"]="ʼ",
["Э"]="E", ["э"]="e",
["Ӭ"]="’E", ["ӭ"]="’e",
["Ю"]="Ju", ["ю"]="ju",
["Я"]="Ja", ["я"]="ja",
}
local vowel = "аӓеёиӣоуӯыэӭюяАӒЕЁИӢОУӮЫЭӬЮЯ"
function export.tr(text, lang, sc)
-- digraphs ie and ea
text = mw.ustring.gsub(text, "([БбВвГгДдЖжЗзКкЛлӅӆМмӍӎНнӉӊӇӈПпРрҎҏТтХхЦцЧчШшЩщ])е" .. macron, "%1иэ")
text = mw.ustring.gsub(text, "([БбВвГгДдЖжЗзКкЛлӅӆМмӍӎНнӉӊӇӈПпРрҎҏТтХхЦцЧчШшЩщ])я" .. macron, "%1эа")
text = mw.ustring.gsub(text, "([БбВвГгДдЖжЗзКкЛлӅӆМмӍӎНнӉӊӇӈПпРрҎҏТтХхЦцЧчШшЩщ])Е" .. macron, "%1Иэ")
text = mw.ustring.gsub(text, "([БбВвГгДдЖжЗзКкЛлӅӆМмӍӎНнӉӊӇӈПпРрҎҏТтХхЦцЧчШшЩщ])Я" .. macron, "%1Эа")
-- initial х → h
text = mw.ustring.gsub(text, "^" .. "х", "h")
text = mw.ustring.gsub(text, "^" .. "Х", "H")
text = mw.ustring.gsub(text, " " .. "х", " h")
text = mw.ustring.gsub(text, " " .. "Х", " H")
-- initial j + vowels
text = mw.ustring.gsub(text, "^" .. "ю" .. macron, "jū")
text = mw.ustring.gsub(text, "^" .. "я" .. macron, "jea")
text = mw.ustring.gsub(text, "^" .. "ӣ", "ji")
text = mw.ustring.gsub(text, "^" .. "е" .. macron, "jie")
text = mw.ustring.gsub(text, "^" .. "Ю" .. macron, "Jū")
text = mw.ustring.gsub(text, "^" .. "Я" .. macron, "Jea")
text = mw.ustring.gsub(text, "^" .. "Ӣ", "Ji")
text = mw.ustring.gsub(text, "^" .. "Е" .. macron, "Jie")
text = mw.ustring.gsub(text, " " .. "ю" .. macron, " jū")
text = mw.ustring.gsub(text, " " .. "я" .. macron, " jea")
text = mw.ustring.gsub(text, " " .. "ӣ", " ji")
text = mw.ustring.gsub(text, " " .. "e" .. macron, " jie")
text = mw.ustring.gsub(text, " " .. "Ю" .. macron, " jū")
text = mw.ustring.gsub(text, " " .. "Я" .. macron, " jea")
text = mw.ustring.gsub(text, " " .. "Ӣ", " ji")
text = mw.ustring.gsub(text, " " .. "E" .. macron, " jie")
--palatal н
text = mw.ustring.gsub(text, "([^" .. vowel .. "НнЪъЬьҌҍ])е", "%1ьэ")
text = mw.ustring.gsub(text, "([^" .. vowel .. "НнЪъЬьҌҍ])ё", "%1ьо")
text = mw.ustring.gsub(text, "([^" .. vowel .. "НнЪъЬьҌҍ])ю", "%1ьу")
text = mw.ustring.gsub(text, "([^" .. vowel .. "НнЪъЬьҌҍ])я", "%1ьа")
text = mw.ustring.gsub(text, "([^" .. vowel .. "НнЪъЬьҌҍ])Е", "%1ЬЭ")
text = mw.ustring.gsub(text, "([^" .. vowel .. "НнЪъЬьҌҍ])Ё", "%1ЬО")
text = mw.ustring.gsub(text, "([^" .. vowel .. "НнЪъЬьҌҍ])Ю", "%1ЬУ")
text = mw.ustring.gsub(text, "([^" .. vowel .. "НнЪъЬьҌҍ])Я", "%1ЬА")
text = mw.ustring.gsub(text, "([нН])ь", "%1й")
text = mw.ustring.gsub(text, "НЬ", "НЙ")
-- дз → ʒ
text = mw.ustring.gsub(text, "дз", "ʒ")
-- дж → ǯ
text = mw.ustring.gsub(text, "дж", "ǯ")
-- replacing the remaining (cyrillic) a's with â's
text = mw.ustring.gsub(text, "а", "â")
return (mw.ustring.gsub(text, '.', tt))
end
return export