Module:shi-Latn-Arab-translit

From Linguifex
Jump to navigation Jump to search

Documentation for this module may be created at Module:shi-Latn-Arab-translit/doc

local export = {}

local tt = {
	["b"] = "ب",
	["g"] = "ڭ",
	["d"] = "د",
	["ḍ"] = "ض",
	["f"] = "ف",
	["k"] = "ك",
	["h"] = "ه",
	["ḥ"] = "ح",
	["ɛ"] = "ع",
	["x"] = "خ",
	["q"] = "ق",
	["j"] = "ج",
	["l"] = "ل",
	["m"] = "م",
	["n"] = "ن",
	["p"] = "پ",
	["r"] = "ر",
	["ṛ"] = "ر",
	["ɣ"] = "غ",
	["s"] = "س",
	["ṣ"] = "ص",
	["t"] = "ت",
	["c"] = "ش",
	["ṭ"] = "ط",
	["v"] = "ڤ",
	["w"] = "و",
	["y"] = "ي",
	["z"] = "ز",
	["ẓ"] = "ژ",
	["ʷ"] = "ُ",
	["e"] = "",
}

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

	if sc == "Latn" then
		text = mw.ustring.lower(text)

		local words = mw.text.split(text, '%s+')
		local result_words = {}

		for _, word in ipairs(words) do
			
            local word = mw.ustring.gsub(word, "([^aiu])%1", "%1ّ")
            
			word = mw.ustring.gsub(word, '.', tt)

			word = mw.ustring.gsub(word, "^a", "آ")
			word = mw.ustring.gsub(word, "^u", "او")
			word = mw.ustring.gsub(word, "^i", "اي")

			word = mw.ustring.gsub(word, "a", "ا")
			word = mw.ustring.gsub(word, "u", "و")
			word = mw.ustring.gsub(word, "i", "ي")

			table.insert(result_words, word)
		end

		text = table.concat(result_words, ' ')
	else
		text = nil
	end

	return text
end

return export