มอดูล:Tirh-translit
หน้าตา
- The following documentation is generated by Module:documentation/functions/translit. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will transliterate text in the อักษรติรหุตา. It is used to transliterate ไมถิลี.
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:Tirh-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 gsub = mw.ustring.gsub
local u = mw.ustring.char
local letter_with_mark = '(.['..u(0x0300)..'-'..u(0x036F)..']?)'
local tt = {
-- consonants
['𑒏'] = 'ก', ['𑒐'] = 'ข', ['𑒑'] = 'ค', ['𑒒'] = 'ฆ', ['𑒓'] = 'ง',
['𑒔'] = 'จ', ['𑒕'] = 'ฉ', ['𑒖'] = 'ช', ['𑒗'] = 'ฌ', ['𑒘'] = 'ญ',
['𑒙'] = 'ฏ', ['𑒚'] = 'ฐ', ['𑒛'] = 'ฑ', ['𑒜'] = 'ฒ', ['𑒝'] = 'ณ',
['𑒞'] = 'ต', ['𑒟'] = 'ถ', ['𑒠'] = 'ท', ['𑒡'] = 'ธ', ['𑒢'] = 'น',
['𑒣'] = 'ป', ['𑒤'] = 'ผ', ['𑒥'] = 'พ', ['𑒦'] = 'ภ', ['𑒧'] = 'ม',
['𑒨'] = 'ย', ['𑒩'] = 'ร', ['𑒪'] = 'ล', ['𑒫'] = 'ว',
['𑒬'] = 'ศ', ['𑒭'] = 'ษ', ['𑒮'] = 'ส', ['𑒯'] = 'ห',
-- independent vowels
['𑒁'] = 'อ', ['𑒂'] = 'อา', ['𑒃'] = 'อิ', ['𑒄'] = 'อี', ['𑒅'] = 'อุ', ['𑒆'] = 'อู',
['𑒇'] = 'ฤ', ['𑒈'] = 'ฤๅ', ['𑒉'] = 'ฦ', ['𑒊'] = 'ฦๅ',
['𑒋'] = 'เอ', ['𑒌'] = 'ไอ', ['𑒍'] = 'โอ', ['𑒎'] = 'เอา',
-- dependent vowels and diacritics (excluding front type)
['𑒰'] = 'า', ['𑒱'] = 'ิ', ['𑒲'] = 'ี', ['𑒳'] = 'ุ', ['𑒴'] = 'ู',
['𑒵'] = 'ฺฤ', ['𑒶'] = 'ฺฤๅ', ['𑒷'] = 'ฺฦ', ['𑒸'] = 'ฺฦๅ',
['𑓀'] = 'ํ', ['𑓁'] = 'ะ', ['𑓂'] = 'ฺ', ['𑓅'] = 'ํ',
['𑓃'] = u(0x0331), -- macron below
['𑒿'] = 'ํ์', -- candrabindu
-- marks
['𑒀'] = '?', ['𑓄'] = '-', ['𑓆'] = '.', ['𑓇'] = 'โอํ์',
-- numerals
['𑓐'] = '0', ['𑓑'] = '1', ['𑓒'] = '2', ['𑓓'] = '3', ['𑓔'] = '4',
['𑓕'] = '5', ['𑓖'] = '6', ['𑓗'] = '7', ['𑓘'] = '8', ['𑓙'] = '9',
-- zero-width space (display it if it hides in a word)
[u(0x200B)] = "‼",
-- zero-width non-joiner and joiner (display it if it hides in a word)
[u(0x200C)] = "₋",
[u(0x200D)] = "₊",
}
local adjust0 = {
-- for convenience
['𑒹'..'𑒺'] = '𑒻', ['𑒹'..'𑒰'] = '𑒼', ['𑒹'..'𑒽'] = '𑒾',
}
local adjust1 = {
-- dependent vowels (front type)
['𑒹'] = 'เ%1', ['𑒺'] = 'เ%1็', ['𑒻'] = 'ไ%1',
['𑒼'] = 'โ%1', ['𑒽'] = 'โ%1็', ['𑒾'] = 'เ%1า',
}
function export.tr(text, lang, sc, debug_mode)
if type(text) == 'table' then -- called directly from a template
text = text.args[1]
end
for k, v in pairs(adjust0) do
text = gsub(text, k, v)
end
text = gsub(text, '.', tt)
for k, v in pairs(adjust1) do
text = gsub(text, letter_with_mark..k, v)
end
text = gsub(text, '([เแไโ])อฺ', 'อฺ%1')
-- ย้ายสัญลักษณ์ขึ้นบน เมื่อมีสระล่าง (ยกเว้นตัวที่ไม่มี)
text = gsub(text, u(0x0331)..'([ุ-ฺ])', u(0x0304)..'%1') -- macron below > macron above
return text
end
return export