Module:Cher-translit

This module will transliterate text in the Cherokee script. It is used to transliterate Cherokee. 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:Cher-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 gsub = mw.ustring.gsub

-- map latin consonants to Cherokee syllables where each consonant maps to a corresponding vowel
local syl_list = {
	-- order of syllables: a, e, i, o, u, v
	[""] = {"Ꭰ", "Ꭱ", "Ꭲ", "Ꭳ", "Ꭴ", "Ꭵ"},
	k = {"Ꭷ"},
	g = {"Ꭶ", "Ꭸ", "Ꭹ", "Ꭺ", "Ꭻ", "Ꭼ"},
	h = {"Ꭽ", "Ꭾ", "Ꭿ", "Ꮀ", "Ꮁ", "Ꮂ"},
	l = {"Ꮃ", "Ꮄ", "Ꮅ", "Ꮆ", "Ꮇ", "Ꮈ"},
	m = {"Ꮉ", "Ꮊ", "Ꮋ", "Ꮌ", "Ꮍ", "Ᏽ"}, -- Ᏽ is obsolete
	n = {"Ꮎ", "Ꮑ", "Ꮒ", "Ꮓ", "Ꮔ", "Ꮕ"},
	hn = {"Ꮏ"},
	qu = {"Ꮖ", "Ꮗ", "Ꮘ", "Ꮙ", "Ꮚ", "Ꮛ"},
	s = {"Ꮜ", "Ꮞ", "Ꮟ", "Ꮠ", "Ꮡ", "Ꮢ"},
	d = {"Ꮣ", "Ꮥ", "Ꮧ", "Ꮩ", "Ꮪ", "Ꮫ"},
	t = {"Ꮤ", "Ꮦ", "Ꮨ"},
	dl = {"Ꮬ"},
	tl = {"Ꮭ", "Ꮮ", "Ꮯ", "Ꮰ", "Ꮱ", "Ꮲ"},
	ts = {"Ꮳ", "Ꮴ", "Ꮵ", "Ꮶ", "Ꮷ", "Ꮸ"},
	w = {"Ꮹ", "Ꮺ", "Ꮻ", "Ꮼ", "Ꮽ", "Ꮾ"},
	y = {"Ꮿ", "Ᏸ", "Ᏹ", "Ᏺ", "Ᏻ", "Ᏼ"}
}

-- vowel order in Cherokee
local vowel_order = {"a", "e", "i", "o", "u", "v"}

-- export for transliteration
function export.tr(text, lang, sc)
	-- ensure all Cherokee characters are uppercase
	text = mw.ustring.upper(text)

	-- substitute values in syl_list dictionary mappings
	for c, v in pairs(syl_list) do
		for i, cher in ipairs(v) do
			text = gsub(text, cher, c .. vowel_order[i])
		end
	end

	-- handle special cases
	-- special case for Ꮐ
	text = gsub(text, "Ꮐna", "nah'na") -- add apostrophe if before Ꮎ
	text = gsub(text, "Ꮐ", "nah") -- otherwise append as is

	-- special case for Ꮝ
	text = gsub(text, "Ꮝ([aeiouv])", "s'%1") -- add apostrophe if before a vowel
	text = gsub(text, "Ꮝ", "s") -- otherwise append as is

	return text
end

return export