模組:Chm-translit
這個模組會將待定語言未確定的文字拉丁化。
最好不要直接從模板或其他模組調用此模組。要從模板中使用它,請以{{xlit}}
做為替代;若要在模組中使用,則以Module:languages#Language:transliterate替代。
關於測試用例,請參閱Module:Chm-translit/testcases。
函數
编辑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, returnsnil
.
local export = {}
local tab = {
["А"]="A", ["Б"]="B", ["В"]="V", ["Г"]="G", ["Д"]="D", ["Е"]="E", ["Ё"]="Jo", ["Ж"]="Ž", ["З"]="Z", ["И"]="I", ["Й"]="J",
["К"]="K", ["Л"]="L", ["М"]="M", ["Н"]="N", ["Ҥ"]="Ŋ", ["О"]="O", ["Ӧ"]="Ö", ["П"]="P", ["Р"]="R", ["С"]="S", ["Т"]="T",
["У"]="U", ["Ӱ"]="Ü", ["Ф"]="F", ["Х"]="H", ["Ц"]="C", ["Ч"]="Č", ["Ш"]="Š", ["Щ"]="Ŝ", ["Ъ"]="", ["Ы"]="Y", ["Ь"]="",
["Э"]="e", ["Ю"]="U", ["Я"]="A",
['а']='a', ['б']='b', ['в']='v', ['г']='g', ['д']='d', ['е']='e', ['ё']='jo', ['ж']='ž', ['з']='z', ['и']='i', ['й']='j',
['к']='k', ['л']='l', ['м']='m', ['н']='n', ['ҥ']='ŋ', ['о']='o', ['ӧ']='ö', ['п']='p', ['р']='r', ['с']='s', ['т']='t',
['у']='u', ['ӱ']='ü', ['ф']='f',
['х']='h', ['ц']='c', ['ч']='č', ['ш']='š', ['щ']='ŝ', ['ъ']='', ['ы']='y', ['ь']='', ['э']='e', ['ю']='u', ['я']='a',
-- Hill (Western) Mari only, doesn't use Ҥ, ҥ
["Ӓ"]="Ä", ["Ӹ"]="Ÿ", ['ӓ']='ä', ['ӹ']='ÿ',
-- Northwestern Mari only
["Ө"]="Ou", ["Ӫ"]="Öü", ['ө']='ou', ['ӫ']='öü',
-- NOTE: non-standart transliteration, please suggest better variants at documentation before replacing
}
function export.tr(text, lang, sc)
-- Ё needs converting if is decomposed
text = text:gsub("ё","ё"):gsub("Ё","Ё")
-- iotated vowels after a vowel or at the beginning of a word become j-
text = mw.ustring.gsub(text, "([АӒОӨÖӪУӰЫӸЕЯЁЮИЕЪЬаӓоөöӫуӱыӹэяёюиеъь%A][\204\129\204\128]?)([еёюя])", "%1j%2")
text = mw.ustring.gsub(text, "^([ЕЁЮЯ])", "J%1")
text = mw.ustring.gsub(text, "^([еёюя])", "j%1")
-- soft consonants
text = mw.ustring.gsub(text, "([НЛнл])([еёияюь])", "%1Q%2")
text = mw.ustring.gsub(text, "НQ", "Ń")
text = mw.ustring.gsub(text, "нQ", "ń")
text = mw.ustring.gsub(text, "ЛQ", "Ĺ")
text = mw.ustring.gsub(text, "лQ", "ĺ")
return (mw.ustring.gsub(text,'.',tab))
end
return export