Module:shn-translit

Hello, you have come here looking for the meaning of the word Module:shn-translit. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:shn-translit, but we will also tell you about its etymology, its characteristics and you will know how to say Module:shn-translit in singular and plural. Everything you need to know about the word Module:shn-translit you have here. The definition of the word Module:shn-translit will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:shn-translit, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

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.

Functions

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns 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