Module:urk-translit

This module will transliterate Urak Lawoi' language text. 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:urk-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 export = {}

local urk = require("Module:urk-common")
local match = mw.ustring.match

local initials = {
	["ก"] = "k",
	["กฺ"] = "g",
	["ค"] = "kh",
	["ง"] = "ng",
	["จ"] = "c",
	["ช"] = "ch",
	["ซ"] = "s",
	["ฌ"] = "ch",  -- nonstandard spellling
	["ญ"] = "ny",
	["ด"] = "d",
	["ต"] = "t",
	["ท"] = "th",
	["น"] = "n",
	["บ"] = "b",
	["ป"] = "p",
	["พ"] = "ph",
	["ฟ"] = "f",
	["ม"] = "m",
	["ย"] = "y",
	["ยฺ"] = "j",
	["ร"] = "r",
	["ล"] = "l",
	["ว"] = "w",
	["อ"] = "ʼ",
	["ฮ"] = "h"
}

local medials = {
	["ร"] = "r",
	["ล"] = "l"
}

local vowels = {
	["อ"] = "ö",
	["เ"] = "ë",
	["เว"] = "aw",
	["เอ"] = "e",
	["เิ"] = "e",
	["เีย"] = "ia",
	["แ"] = "ä",
	["โ"] = "o",
	["ั"] = "a",
	["ัว"] = "ua",
	["า"] = "a",
	["ิ"] = "i",
	["ี"] = "i",
	["ึ"] = "e", -- nonstandard spelling
	["ื"] = "e",
	["ุ"] = "u",
	["ู"] = "u"
}

local finals = {
	["ก"] = "k",
	["ง"] = "ng",
	["จ"] = "c", -- alterative spelling
	["ด"] = "t",
	["น"] = "n",
	["บ"] = "p",
	["ม"] = "m",
	["ย"] = "y",
	["ยจ"] = "c",
	["ยฮ"] = "s",
	["ยํ"] = "l", -- variable pronunciation
	["ล"] = "l", -- only in phuket
	["ว"] = "w",
	["ฮ"] = "h",
	["ะ"] = "q",
	["ะฮ"] = "h" -- alterative spelling
}

-- main function
function export.tr(text, lang, sc)
	local translit = ""
	local respelt = urk.syllabise(text, true)

	for _, segment in ipairs(respelt) do
		if match(segment, "[ก-๎]") then
			local v_pref, i, m, v_suf, f_pref, f_suf = match(segment, urk.syllable_pattern)

			local v = v_pref .. v_suf
			-- special case for "เีย"
			if v_pref == "เ" and v_suf == "ี" and f_pref == "ย" then
				v = "เีย"
				f_pref = ""
			end
			local f = f_pref .. f_suf

			-- join components together
			translit = translit .. (initials[i] or "") .. (medials[m] or "") .. (vowels[v] or "") .. (finals[f] or "")
		else
			translit = translit .. segment
		end
	end

	return translit
end

return export