模組:Glag-translit
這個模組會將待定語言未確定的文字拉丁化。
最好不要直接從模板或其他模組調用此模組。要從模板中使用它,請以{{xlit}}
做為替代;若要在模組中使用,則以Module:languages#Language:transliterate替代。
關於測試用例,請參閱Module:Glag-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 letters = {}
local digraphs = {}
letters["Glag"] = {
["Ⰰ"]='A', ["ⰰ"]='a', ["Ⱝ"]='A', ["ⱝ"]='a',
["Ⰱ"]='B', ["ⰱ"]='b',
["Ⰲ"]='V', ["ⰲ"]='v',
["Ⰳ"]='G', ["ⰳ"]='g',
["Ⰴ"]='D', ["ⰴ"]='d',
["Ⰵ"]='E', ["ⰵ"]='e',
["Ⰶ"]='Ž', ["ⰶ"]='ž',
["Ⰷ"]='Dz', ["ⰷ"]='dz',
["Ⰸ"]='Z', ["ⰸ"]='z',
["Ⰹ"]='I', ["ⰹ"]='i', ["Ⰺ"]='I', ["ⰺ"]='i', ["Ⰻ"]='I', ["ⰻ"]='i',
["Ⰼ"]='Đ', ["ⰼ"]='đ',
["Ⰽ"]='K', ["ⰽ"]='k',
["Ⰾ"]='L', ["ⰾ"]='l',
["Ⰿ"]='M', ["ⰿ"]='m', ["Ⱞ"]='M', ["ⱞ"]='m',
["Ⱀ"]='N', ["ⱀ"]='n',
["Ⱁ"]='O', ["ⱁ"]='o', ["Ⱉ"]='O', ["ⱉ"]='o',
["Ⱂ"]='P', ["ⱂ"]='p',
["Ⱃ"]='R', ["ⱃ"]='r',
["Ⱄ"]='S', ["ⱄ"]='s',
["Ⱅ"]='T', ["ⱅ"]='t',
["Ⱆ"]='U', ["ⱆ"]='u',
["Ⱇ"]='F', ["ⱇ"]='f',
["Ⱈ"]='X', ["ⱈ"]='x', ["Ⱒ"]='X', ["ⱒ"]='x',
["Ⱌ"]='C', ["ⱌ"]='c',
["Ⱍ"]='Č', ["ⱍ"]='č',
["Ⱎ"]='Š', ["ⱎ"]='š',
-- For Ⱋ see below
["Ⱏ"]='Ŭ', ["ⱏ"]='ŭ',
["Ⱐ"]='Ĭ', ["ⱐ"]='ĭ', ["Ⱜ"]='Ĭ', ["ⱜ"]='ĭ',
["Ⱑ"]='Ě', ["ⱑ"]='ě',
["Ⱓ"]='Ju', ["ⱓ"]='ju',
["Ⱔ"]='Ę', ["ⱔ"]='ę',
["Ⱕ"]='Y̨', ["ⱕ"]='y̨',
["Ⱗ"]='Ję', ["ⱗ"]='ję',
["Ⱘ"]='Ǫ', ["ⱘ"]='ǫ', ["Ⱖ"]='Ǫ', ["ⱖ"]='ǫ',
["Ⱙ"]='Jǫ', ["ⱙ"]='jǫ',
["Ⱚ"]='Θ', ["ⱚ"]='θ',
["Ⱛ"]='Ü', ["ⱛ"]='ü',
}
digraphs["Glag"] = {
["Ⱏ[ⰉⰊⰋⰹⰺⰻ]"]="Y", ["ⱏ[ⰹⰺⰻ]"]="y",
}
function export.tr(text, lang, sc)
if not sc then
sc = require("Module:languages").getByCode(lang):findBestScript(text):getCode()
end
-- Щ was pronounced differently in Old Church Slavonic
if lang == "cu" then
letters["Glag"]["Ⱋ"]='Št'
letters["Glag"]["ⱋ"]='št'
else
letters["Glag"]["Ⱋ"]='Šč'
letters["Glag"]["ⱋ"]='šč'
end
-- Transliterate the titlo as colon
text = string.gsub(text, mw.ustring.char(0x0483), ":")
if sc == "Glag" then
for key, repl in pairs(digraphs[sc]) do
text = mw.ustring.gsub(text, key, repl)
end
-- pattern for one non-ASCII character
text = string.gsub(text, '[\194-\244][\128-\191]+', letters[sc])
end
return text
end
return export