Jump to content

Module:Lisu-translit

Wiktionary වෙතින්

This module will transliterate text in the Fraser අක්ෂරක්‍රමය. It is used to transliterate Zaiwa, Lisu, and Naxi. 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:Lisu-translit/testcases.

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.

--[==[
Transliteration scheme is that used in David Bradley's Southern Lisu Dictionary (2006): https://stedt.berkeley.edu/pubs_and_prods/STEDT_Monograph4_Southern-Lisu-Dict.pdf ]==]

local export = {}
local gsub = mw.ustring.gsub

local oneChar = {
	["ꓐ"] = "b", ["ꓑ"] = "p", ["ꓒ"] = "pʰ", ["ꓓ"] = "d", ["ꓔ"] = "t", ["ꓕ"] = "tʰ", ["ꓖ"] = "g", ["ꓗ"] = "k", ["ꓘ"] = "kʰ", ["ꓙ"] = "dʒ", ["ꓚ"] = "tʃ", ["ꓛ"] = "tʃʰ", ["ꓜ"] = "dz", ["ꓝ"] = "ts", ["ꓞ"] = "tsʰ", ["ꓟ"] = "m", ["ꓠ"] = "n", ["ꓡ"] = "l", ["ꓢ"] = "s", ["ꓣ"] = "ʐ", ["ꓤ"] = "z", ["ꓥ"] = "ŋ", ["ꓦ"] = "h̃", ["ꓧ"] = "x", ["ꓨ"] = "h", ["ꓩ"] = "f", ["ꓪ"] = "w", ["ꓫ"] = "ʃ", ["ꓬ"] = "j", ["𑾰"] = "jʰ", ["ꓭ"] = "ɣ",
	["ꓮ"] = "ɑ", ["ꓯ"] = "æ", ["ꓰ"] = "e", ["ꓱ"] = "ø", ["ꓲ"] = "i", ["ꓳ"] = "o", ["ꓴ"] = "u", ["ꓵ"] = "y", ["ꓶ"] = "ɯ", ["ꓷ"] = "ɤ",
	["ꓸ"] = "́", ["ꓹ"] = "̌", ["ꓺ"] = "̱", ["ꓻ"] = "", ["ꓼ"] = "̱̀", ["ꓽ"] = "̀",
	["ʼ"] = "̃", ["ˍ"] = "ɑ",
	["꓾"] = ",", ["꓿"] = ".",
}

local twoChars = {
	["ꓠꓬ"] = "ɲ",
}

local threeChars = {
	["ꓙ\1ꓮ"] = "dʐɑ", ["ꓚ\1ꓮ"] = "tʂɑ", ["ꓛ\1ꓮ"] = "tʂʰɑ", ["ꓫ\1ꓮ"] = "ʂɑ",
	["ꓙꓬꓮ"] = "dʒɑ", ["ꓚꓬꓮ"] = "tʃɑ", ["ꓛꓬꓮ"] = "tʃʰɑ", ["ꓫꓬꓮ"] = "ʃɑ",
	["ꓺꓽ꓿"] = "ꓺꓽ?"
}

function export.tr(text, lang, sc)
	local UTF8_char = "[%z\1-\127\194-\244][\128-\191]*"
	
	text = gsub(text, "([ꓮ-ꓷ])([ꓐ-ꓭ𑾰])([ꓸ-ꓽ]+)", "%1%3%2")
	text = gsub(text, "([ꓮ-ꓷ])([ꓮ-ꓷ])([ꓸ-ꓽ])", "%1%3%2")
	text = gsub(text, "%f[^%z%s%-꓾꓿][ꓐ-ꓭ𑾰]+%f[%z%s%-ꓸ-꓿ʼˍ]", "%0ꓮ")
	text = gsub(text, "ˍ%f[%z%s%-꓾꓿ʼ]", "%0ꓺ")
	text = gsub(text, "([ꓮ-ꓷˍ])([ꓸ-ꓽ])([ꓸ-ꓽ])", "%1%2%1%3")
	text = gsub(text, "%f[^%z%s꓾꓿]([ꓶꓷ])", "ɣ%1")
	text = gsub(text, "ꓮ([ꓸ-ꓽ]+)([ꓶꓷ])", "%2%1")
	text = gsub(text, "([ꓜꓝꓞꓢꓣꓤ])ꓲ", "%1ɨ")
	text = gsub(text, "([ꓙꓚꓛꓫ])ꓵ", "%1ɨ")
	text = gsub(text, "([ꓜꓝꓞꓢꓣꓤ])ꓬ(ꓲ)", "%1%2")
	text = gsub(text, "([ꓙꓚꓛꓫ])ꓬ(ꓵ)", "%1%2")
	text = gsub(text, "([ꓮ-ꓷ][ꓸ-ꓽ]?)ꓲ%f[%z%s]", "%1j")
	text = gsub(text, "([ꓮ-ꓷ][ꓸ-ꓽ]?)ꓳ%f[%z%s]", "%1w")
	text = gsub(text, "([ꓙꓚꓛꓫ])(ꓮ[ꓸ-ꓽ]?)%f[^ꓮ-ꓷjwɨꓸ-ꓽ]", "%1\1%2")
	
	for trigraph, replacement in pairs(threeChars) do
		text = text:gsub(trigraph, replacement)
	end
	
	for digraph, replacement in pairs(twoChars) do
		text = text:gsub(digraph, replacement)
	end
	
	return (text:gsub(UTF8_char, oneChar))
end

return export
"https://si.wiktionary.org/w/index.php?title=Module:Lisu-translit&oldid=196281" වෙතින් සම්ප්‍රවේශනය කෙරිණි