Module:zkt-translit

This module will transliterate Khitan 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:zkt-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 data = mw.loadData("Module:zkt-translit/data")

function export.tr(text, lang, sc)
	-- Remove text formatting.
	text = text:gsub("\244[\128-\191][\128-\191][\128-\191]", "")
	
	local trtab = {}
	
	i = 0
	for char in mw.ustring.gmatch(text, ".") do
		i = i + 1
		if char == "𘬀" and i > 1 then
			table.insert(trtab, trtab[i-1])
		else
			table.insert(trtab, data[char] or "?")
		end
	end
	local check = table.concat(trtab)
	_, count = mw.ustring.gsub(check, "?", "")
	if count == mw.ustring.len(check) then
		return nil
	else
		return "*" .. table.concat(trtab, " ")
	end
end

return export