Module:Tavt-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate text in the Tai Viet script. 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:Tavt-translit/testcases.

Functions

[edit]
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 export = {}
local gsub = mw.ustring.gsub

local tt = {
	-- consonants
	["ꪀ"] = "k", ["ꪁ"] = "ḵ", ["ꪂ"] = "k̄h", ["ꪃ"] = "kh", ["ꪄ"] = "ḳ̄h", ["ꪅ"] = "kʹh", ["ꪆ"] = "?", ["ꪇ"] = "?", ["ꪈ"] = "h̄ng", ["ꪉ"] = "ng",
	["ꪊ"] = "c", ["ꪋ"] = "c̱", ["ꪌ"] = "c̄h", ["ꪍ"] = "ch", ["ꪎ"] = "s̄", ["ꪏ"] = "s", ["ꪐ"] = "h̄ỵ", ["ꪑ"] = "ỵ",
	["ꪒ"] = "d", ["ꪓ"] = "ḏ", ["ꪔ"] = "t", ["ꪕ"] = "ṯ", ["ꪖ"] = "t̄h", ["ꪗ"] = "th", ["ꪘ"] = "h̄n", ["ꪙ"] = "n",
	["ꪚ"] = "b", ["ꪛ"] = "ḇ", ["ꪜ"] = "p", ["ꪝ"] = "p̱", ["ꪞ"] = "p̄h", ["ꪟ"] = "ph", ["ꪠ"] = "f̄", ["ꪡ"] = "f", ["ꪢ"] = "h̄m", ["ꪣ"] = "m",
	["ꪤ"] = "h̄y", ["ꪥ"] = "y", ["ꪦ"] = "h̄r", ["ꪧ"] = "r", ["ꪨ"] = "h̄l", ["ꪩ"] = "l", ["ꪪ"] = "h̄w", ["ꪫ"] = "w",
	["ꪬ"] = "h̄", ["ꪭ"] = "ḥ", ["ꪮ"] = "x", ["ꪯ"] = "x̱",
	-- vowels and finals (visual ordering)
	["ꪰ"] = "'", ["ꪱ"] = "ā", ["ꪲ"] = "l", ["ꪳ"] = "ụ", ["ꪴ"] = "ุ", ["ꪵ"] = "æ", ["ꪶ"] = "o",
	["ꪷ"] = "'", ["ꪸ"] = "y", ["ꪹ"] = "e", ["ꪺ"] = "ัw", ["ꪻ"] = "i", ["ꪼ"] = "ị",
	["ꪽ"] = "ัn", ["ꪾ"] = "ả",
	-- tones
	["꪿"] = "'", ["ꫀ"] = "<sup>1</sup>", ["꫁"] = "'", ["ꫂ"] = "<sup>2</sup>",
	-- symbols
	["ꫛ"] = "ko̱n", ["ꫜ"] = "nụ̀ng", ["ꫝ"] = "«", ["꫞"] = "§", ["꫟"] = "»",
}

function export.tr(text, lang, sc)

	if type(text) == "table" then -- called directly from a template
		text = text.args[1]
	end

	text = gsub(text, ".", tt)

	text = gsub(text, "([่้๋̱])([ัิีึืุู])", "%2%1")
	text = gsub(text, "([^%s%p%z])bả", "%1ัb")
	text = gsub(text, "(ả)([่้๋̱])", "%2%1")

	return text

end

return export