มอดูล:Mymr-translit
- The following documentation is located at มอดูล:Mymr-translit/documentation. [edit] Categories were auto-generated by Module:module categorization. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will transliterate text in the อักษรพม่า. It is used to transliterate บาลี and สันสกฤต.
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:Mymr-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)
["ါ"] = "า", ["ာ"] = "า", ["ိ"] = "ิ", ["ီ"] = "ี", ["ု"] = "ุ", ["ူ"] = "ู",
["ဳ"] = "ี", ["ံ"] = "ํ", ["့"] = "̥", ["း"] = ":", ["္"] = "ฺ", ["်"] = "์",
["ျ"] = "ฺย", ["ြ"] = "ฺร", ["ွ"] = "ฺว", --["ှ"] = "ฺห",
["ၖ"] = "ฺฤ", ["ၗ"] = "ฺฤๅ", ["ၘ"] = "ฺฦ", ["ၙ"] = "ฺฦๅ",
["ၞ"] = "ฺน", ["ၟ"] = "ฺม", ["ၠ"] = "ฺล",
["ၢ"] = "า", ["ၣ"] = "�", ["ၤ"] = "�",
["ၧ"] = "�", ["ၨ"] = "ึ", ["ၩ"] = "¹", ["ၪ"] = "²", ["ၫ"] = "³", ["ၬ"] = "⁴", ["ၭ"] = "⁵",
["ၱ"] = "ิ", ["ၳ"] = "ุ",
["ႂ"] = "ฺว", ["ႃ"] = "า", ["ႆ"] = "ย",
["ႇ"] = "²", ["ႈ"] = "³", ["ႉ"] = "⁵", ["ႊ"] = "⁶", ["ႋ"] = "²", ["ႌ"] = "³", ["ႍ"] = "̲",
["ႏ"] = "⁵",
["ႚ"] = "¹", ["ႛ"] = "³", ["ႜ"] = "ะ", ["ႝ"] = "า",
["ꩻ"] = "¹", ["ꩼ"] = "²", ["ꩽ"] = "⁵",
["ꧥ"] = "�",
-- marks
["၊"] = ",", ["။"] = ".",
["၌"] = "@", ["၍"] = ";", ["၎"] = "ฯ", ["၏"] = ".",
["႟"] = "!", ["ꩰ"] = "ๆ", ["꩷"] = "!", ["ꧦ"] = "ๆ",
-- numerals
["၀"] = "๐", ["၁"] = "๑", ["၂"] = "๒", ["၃"] = "๓", ["၄"] = "๔",
["၅"] = "๕", ["၆"] = "๖", ["၇"] = "๗", ["၈"] = "๘", ["၉"] = "๙",
["႐"] = "0", ["႑"] = "1", ["႒"] = "2", ["႓"] = "3", ["႔"] = "4",
["႕"] = "5", ["႖"] = "6", ["႗"] = "7", ["႘"] = "8", ["႙"] = "9",
["႞"] = "1",
["꩸"] = "๑", ["꩹"] = "๒",
["꧰"] = "๐", ["꧱"] = "๑", ["꧲"] = "๒", ["꧳"] = "๓", ["꧴"] = "๔",
["꧵"] = "๕", ["꧶"] = "๖", ["꧷"] = "๗", ["꧸"] = "๘", ["꧹"] = "๙",
-- zero-width space (display it if it hides in a word)
[u(0x200B)] = "‼",
}
local adjust1 = {
-- dependent vowels (front type)
["ေ"] = "เ%1", ["ဲ"] = "แ%1", ["ဴ"] = "โ%1", ["ဵ"] = "เ%1",
["ၲ"] = "เ%1อ̂", ["ၴ"] = "เ%1", ["ႄ"] = "เ%1", ["ႅ"] = "เ%1",
-- other
["ှ"] = "หฺ%1",
}
function export.tr(text, lang, sc, debug_mode)
if type(text) == "table" then -- called directly from a template
text = text.args[1]
end
if lang == "my" then
text = gsub(text, "ရ([ျြွ]?)ှ", "ၡ%1") -- หฺร -> ศ
end
text = gsub(text, "(့)([ါ-ှ])", "%2%1") -- swap tone-3 mark and vowel
text = gsub(text, ".", tt)
for k, v in pairs(adjust1) do
text = gsub(text, letter_with_mark..k, v)
end
if lang == "my" then
text = gsub(text, letter_with_mark.."ิุ", "โ%1") -- อิุ -> โอ
text = gsub(text, "โ"..letter_with_mark.."([ก-รวศษสฬอ]์)", "ไ%1%2") -- โอx์ -> ไอx์ ยกเว้น ลหฮ
text = gsub(text, "เ"..letter_with_mark.."า", "%1อ̂") -- เอา -> ออ̂
text = gsub(text, "^"..letter_with_mark.."อ̂์", "เ%1าะ") -- ออ̂์ -> เอาะ
text = gsub(text, "([^เ])"..letter_with_mark.."อ̂์", "%1เ%2าะ") -- ออ̂์ -> เอาะ
text = gsub(text, "^"..letter_with_mark.."อ̂([ก-ฮ]์)", "เ%1า%2") -- ออ̂x์ -> เอาx์
text = gsub(text, "([^เ])"..letter_with_mark.."อ̂([ก-ฮ]์)", "%1เ%2า%3") -- ออ̂x์ -> เอาx์
end
if lang == "pi" then
text = gsub(text, "เ"..letter_with_mark.."า", "โ%1") -- เอา -> โอ --TODO: what about "au" in Sanskrit?
end
text = gsub(text, "([เแไโ])อฺ", "อฺ%1")
text = gsub(text, "([¹²³⁴⁵⁶])์", "์%1")
return text
end
return export