模組:Latn-Tfng-translit


這個模組將轉寫拉丁字母當中的文字。 最好不要直接從模板或其他模組呼叫此模組;要從模板中使用它, 請使用{{xlit}}; 要從模組中使用它,請使用Module:languages#Language:transliterate

關於測試用例,請見Module:Latn-Tfng-translit/testcases

函式

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["Latn"] = {
	["common"] = {
		["a"] = "ⴰ",
		["ā"] = "ⴰⴰ",
		["b"] = "ⴱ",
		["ḇ"] = "ⴲ",
		["ǧ"] = "ⴵ",
		["g"] = "ⴳ",
		["d"] = "ⴷ",
		["ḏ"] = "ⴸ",
		["ḍ"] = "ⴹ",
		["ḏ̣"] = "ⴺ",
		["e"] = "ⴻ",
		["f"] = "ⴼ",
		["k"] = "ⴽ",
		["h"] = "ⵀ",
		["ḥ"] = "ⵃ",
		["ɛ"] = "ⵄ",
		["x"] = "ⵅ",
		["q"] = "ⵇ",
		["i"] = "ⵉ",
		["j"] = "ⵊ",
		["l"] = "ⵍ",
		["m"] = "ⵎ",
		["n"] = "ⵏ",
		["p"] = "ⵒ",
		["u"] = "ⵓ",
		["r"] = "ⵔ",
		["ř"] = "ⵔ",
		["ṛ"] = "ⵕ",
		["ɣ"] = "ⵖ",
		["s"] = "ⵙ",
		["ṣ"] = "ⵚ",
		["t"] = "ⵜ",
		["ṯ"] = "ⵝ",
		["š"] = "ⵛ",
		["c"] = "ⵛ",
		["č"] = "ⵞ",
		["ṭ"] = "ⵟ",
		["v"] = "ⵠ",
		["w"] = "ⵡ",
		["y"] = "ⵢ",
		["z"] = "ⵣ",
		["ẓ"] = "ⵥ",
		["o"] = "ⵧ",
		["ʷ"] = "ⵯ",
		["."] = "⵰",
	},
	["tmh"] = {["b"] = "ⵀ", ["w"] = "ⵓ"},
	["thv"] = {["b"] = "ⵀ", ["w"] = "ⵓ"},
	["taq"] = {["b"] = "ⵀ", ["w"] = "ⵓ"},
	["ttq"] = {["b"] = "ⵀ", ["w"] = "ⵓ"},
	["thz"] = {["b"] = "ⵀ", ["w"] = "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 == "Latn" then
		text = mw.ustring.lower(text)
		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

return export