Module:Tfng-translit

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module will transliterate text in the Tifinagh script. It is used to transliterate Ghomara, 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.

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

tt["Tfng"] = {
	["common"] = {
		["ⴰ"] = "a",
		["ⴱ"] = "b",
		["ⴲ"] = "ḇ",
		["ⴳ"] = "g",
		["ⴴ"] = "g",
		["ⴵ"] = "ǧ",
		["ⴶ"] = "ǧ",
		["ⴷ"] = "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",
		["ⵝ"] = "ṯ",
		["ⵛ"] = "c",
		["ⵞ"] = "č",
		["ⵟ"] = "ṭ",
		["ⵠ"] = "v",
		["ⵡ"] = "w",
		["ⵢ"] = "y",
		["ⵣ"] = "z",
		["ⵤ"] = "z",
		["ⵥ"] = "ẓ",
		["ⵦ"] = "e",
		["ⵧ"] = "o",
		["ⵯ"] = "ʷ",
		["⵰"] = ".",
		["⵿"] = ""
	},
	["tmh"] = {["ⵀ"] = "b", ["ⵓ"] = "w"},
	["thv"] = {["ⵀ"] = "b", ["ⵓ"] = "w"},
	["taq"] = {["ⵀ"] = "b", ["ⵓ"] = "w"},
	["ttq"] = {["ⵀ"] = "b", ["ⵓ"] = "w"},
	["thz"] = {["ⵀ"] = "b", ["ⵓ"] = "w", ["ⵘ"] = "ɣ"}
}

function export.tr(text, lang, sc)
	if not sc then
		sc = require("Module:languages").getByCode(lang or "ber"):findBestScript(text):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