Module:Tfng-translit

This module will transliterate text in the Tifinagh script. It is used to transliterate Tarifit, Tashelhit, Tachawit, Central Atlas Tamazight, and Moroccan Amazigh.

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:Tfng-translit/testcases.

FunctionsEdit

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 tt = {}

tt["Tfng"] = {
	["common"] = {
		["ⴰ"] = "a",
		["ⴱ"] = "b",
		["ⴲ"] = "b",
		["ⴳ"] = "g",
		["ⴴ"] = "g",
		["ⴵ"] = "ǧ",
		["ⴶ"] = "ǧ",
		["ⴷ"] = "d",
		["ⴸ"] = "d",
		["ⴹ"] = "ḍ",
		["ⴺ"] = "ḍ",
		["ⴻ"] = "e",
		["ⴼ"] = "f",
		["ⴽ"] = "k",
		["ⴾ"] = "k",
		["ⴿ"] = "k",
		["ⵀ"] = "h", -- tmh, thv, taq, ttq, thz: "b"
		["ⵁ"] = "h",
		["ⵂ"] = "h",
		["ⵃ"] = "ḥ",
		["ⵄ"] = "ɛ",
		["ⵅ"] = "x",
		["ⵆ"] = "x",
		["ⵇ"] = "q",
		["ⵈ"] = "q",
		["ⵉ"] = "i",
		["ⵊ"] = "j",
		["ⵋ"] = "j",
		["ⵌ"] = "j",
		["ⵍ"] = "l",
		["ⵎ"] = "m",
		["ⵏ"] = "n",
		["ⵐ"] = "ny",
		["ⵑ"] = "ng",
		["ⵒ"] = "p",
		["ⵓ"] = "u", -- tmh, thv, taq, ttq, thz: "w"
		["ⵔ"] = "r",
		["ⵕ"] = "ṛ",
		["ⵖ"] = "ɣ",
		["ⵗ"] = "ɣ",
		["ⵘ"] = "j", -- thz: "ɣ"
		["ⵙ"] = "s",
		["ⵚ"] = "ṣ",
		["ⵛ"] = "š",
		["ⵜ"] = "t",
		["ⵝ"] = "t",
		["ⵞ"] = "č",
		["ⵟ"] = "ṭ",
		["ⵠ"] = "v",
		["ⵡ"] = "w",
		["ⵢ"] = "y",
		["ⵣ"] = "z",
		["ⵤ"] = "z",
		["ⵥ"] = "ẓ",
		["ⵦ"] = "e",
		["ⵧ"] = "o",
		["ⵯ"] = "ʷ",
		["⵰"] = ".",
		["⵿"] = ""
	},
	["tmh"] = {["ⵀ"] = "b", ["ⵓ"] = "w"},
	["thv"] = {["ⵀ"] = "b", ["ⵓ"] = "w"},
	["taq"] = {["ⵀ"] = "b", ["ⵓ"] = "w"},
	["ttq"] = {["ⵀ"] = "b", ["ⵓ"] = "w"},
	["thz"] = {["ⵀ"] = "b", ["ⵓ"] = "w", ["ⵘ"] = "ɣ"}
}

tt["Latn"] = {
	["common"] = {
		["a"] = "ⴰ",
		["ā"] = "ⴰ",
		["b"] = "ⴱ",
		["g"] = "ⴳ",
		["d"] = "ⴷ",
		["ḏ"] = "ⴷ",
		["ḍ"] = "ⴹ",
		["e"] = "ⴻ",
		["f"] = "ⴼ",
		["ǧ"] = "ⴵ",
		["k"] = "ⴽ",
		["h"] = "ⵀ",
		["ḥ"] = "ⵃ",
		["ɛ"] = "ⵄ",
		["x"] = "ⵅ",
		["q"] = "ⵇ",
		["i"] = "ⵉ",
		["j"] = "ⵊ",
		["l"] = "ⵍ",
		["m"] = "ⵎ",
		["n"] = "ⵏ",
		["p"] = "ⵒ",
		["u"] = "ⵓ",
		["r"] = "ⵔ",
		["ṛ"] = "ⵕ",
		["ɣ"] = "ⵖ",
		["s"] = "ⵙ",
		["ṣ"] = "ⵚ",
		["š"] = "ⵛ",
		["t"] = "ⵜ",
		["ṯ"] = "ⵜ",
		["č"] = "ⵞ",
		["ṭ"] = "ⵟ",
		["v"] = "ⵠ",
		["w"] = "ⵡ",
		["y"] = "ⵢ",
		["z"] = "ⵣ",
		["ẓ"] = "ⵥ",
		["o"] = "ⵧ",
		["ʷ"] = "ⵯ",
		["."] = "⵰",
	},
	["tmh"] = {["b"] = "ⵀ", ["w"] = "ⵓ"},
	["thv"] = {["b"] = "ⵀ", ["w"] = "ⵓ"},
	["taq"] = {["b"] = "ⵀ", ["w"] = "ⵓ"},
	["ttq"] = {["b"] = "ⵀ", ["w"] = "ⵓ"},
	["thz"] = {["b"] = "ⵀ", ["w"] = "wⵓ", ["ɣ"] = "ⵘ"}
}

function export.tr_alt(text, lang, sc)
	if not sc then
		sc = require("Module:scripts").findBestScript(text, require("Module:languages").getByCode(lang or "ber")):getCode()
	end

	if sc == "Latn" then
		if tt[sc][lang] then
			text = mw.ustring.gsub(text, '.', tt[sc][lang])
		end
		text = mw.ustring.gsub(text, '.', tt[sc]["common"])
	else
		text = nil
	end

	return text
end

function export.tr(text, lang, sc)
	if not sc then
		sc = require("Module:scripts").findBestScript(text, require("Module:languages").getByCode(lang or "ber")):getCode()
	end

	if sc ~= "Tfng" then
		text = nil
	else
		if tt[sc][lang] then
			text = mw.ustring.gsub(text, '.', tt[sc][lang])
		end
		text = mw.ustring.gsub(text, '.', tt[sc]["common"])
	end

	return text
end

return export