Module:User:Marzgaoui45/Tfng-translit

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 replace_char(pos, str, r) return mw.ustring.sub(str, 1, pos-1) .. r .. mw.ustring.sub(str, pos+1) end

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 return nil else if tt[sc][lang] then text = mw.ustring.gsub(text, '.', tt[sc][lang]) end text = mw.ustring.gsub(text, '.', tt[sc]["common"])

-- Remove ⴻ, ⴻ only allowed when the absence creates confusion in pronounciation. -- Examples where ⴻ stays: ⵉⵜⴻⵜⵜ, ⵜⵓⴽⴽⵡⴷⴻⴷ, ⵎⴻⵎⵎⵉ, ⵉⵍⴻⵍ start_index = 0

while true do			start_index, _ = mw.ustring.find(text, 'ⴻ', start_index+1) if start_index == nil then return text end index_m1 = mw.ustring.sub(text, start_index-1, start_index-1) index_p1 = mw.ustring.sub(text, start_index+1, start_index+1) if index_m1 ~= index_p1 then text = replace_char(start_index, text, 'ⴻ') end end end end

return export