This module will transliterate Shan language text per Wiktionary:Shan transliteration per WT:SHN TR.
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:shn-translit/testcases.
tr(text, lang, sc)
text
written in the script specified by the code sc
, and language specified by the code lang
.nil
.local gsub = mw.ustring.gsub
local match = mw.ustring.match
local u = require("Module:string/char")
local export = {}
local initial_table = {
= "k", = "kh", = "g", = "gh", = "ng",
= "ts", = "tsh", = "z", = "zh", = "ny",
= "tt", = "tth", = "dd", = "ddh", = "nn",
= "t", = "th", = "d", = "dh", = "n",
= "p", = "ph", = "f", = "b", = "bh", = "m",
= "y", = "r", = "l", = "w",
= "x", = "s", = "h", = "ll", = "ʼ", --U+02BC
}
local glide_table = {
= "j",
= "r",
= "w",
= "",
}
local vowel_table = {
= "a",
= "aa",
= "i",
= "ae",
= "e",
= "u",
= "uu",
= "au",
= "ue",
= "oe",
= "aa",
= "ii",
= "ee",
= "aae",
= "o",
= "au",
= "ue",
= "oe",
= "ai",
= "aai",
= "aai",
= "ui",
= "oi",
= "aui",
= "uei",
= "oei",
= "ao",
= "aao",
= "io",
= "aeo",
= "eao",
= "aue",
}
local coda_table = {
= "m",
= "n",
= "ng",
= "p",
= "t",
= "k",
= "",
}
local tone_table = {
= u(0x030C),
= u(0x0300),
= u(0x0304),
= u(0x0301),
= u(0x0302) .. u(0x0330),
= u(0x1DC8),
}
local digits = {
= "0", = "1", = "2", = "3", = "4",
= "5", = "6", = "7", = "8", = "9",
= "0", = "1", = "2", = "3", = "4",
= "5", = "6", = "7", = "8", = "9",
}
local syllable_pattern =
"^()" ..
"(?)" ..
"(*)" ..
"(?်?)" ..
"(?)$"
local repeat_syllabify =
"()()"
function export.tr(text, lang, sc)
text = gsub(text, ".", digits)
while match(text, repeat_syllabify) do
text = gsub(text, repeat_syllabify, "%1 %2")
end
local new, untoned
for old in mw.text.gsplit(text, " ") do
new = gsub(old, syllable_pattern, function(initial, glide, vowel, coda, tone)
untoned = initial_table ..
(vowel_table or
glide_table ..
(vowel_table or
(vowel_table or vowel) ..
(coda_table or coda)))
return gsub(untoned, "()", "%1" .. tone_table, 1)
end)
text = gsub(text, old, new, 1)
end
if not match(text, "") then
return text
else
return nil
end
end
return export