Module:User:Sameerhameedy/fa-IPA-ira
- This module sandbox lacks a documentation subpage. You may create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • user page • user talk page • userspace
This is a private module sandbox of Sameerhameedy, for their own experimentation. Items in this module may be added and removed at Sameerhameedy's discretion; do not rely on this module's stability.
local rsubn = mw.ustring.gsub
local U = mw.ustring.char
local export = {}
local zabar = U(0x64E)
local zer = U(0x650)
local pesh = U(0x64F)
local tashdid = U(0x651) -- also called shadda
local jazm = U(0x652) -- sukoon
local he = "ه"
local zwnj = U(0x200C)
local highhmz = U(0x654)
local convert_consonants = {
-- STOP! fa-IPA should remove incorrect characters,
-- if an incorrect character is appearing, check fa_IPA not here
["β"] = "ب",
["ð"] = "د",
["b"] = "ب",
["č"] = "چ",
["d"] = "د",
["f"] = "ف",
["g"] = "گ",
["ğ"] = "غ",
["h"] = he,
["j"] = "ج",
["k"] = "ک",
["l"] = "ل",
["m"] = "م",
["n"] = "ن",
["p"] = "پ",
["q"] = "ق",
["r"] = "ر",
["s"] = "س",
["š"] = "ش",
["t"] = "ت",
["ɖ"] = "د", --only for Hazaragi
["ʈ"] = "ت", --only for Hazaragi
["w"] = "و",
["x"] = "خ",
["y"] = "ی",
["z"] = "ز",
["ž"] = "ژ",
["'"] = "ئ",
}
local convert_vowels = {
["a"] = zabar, ["â"] = "ا", ["e"] = zer,
["o"] = pesh, ["u"] = "و", ["i"] = "ی",
}
local vowels = "aeoiu" --including â causes issues
local consonants = "bptjčxdrzžsš'ğfqkglmnwvwhy"
local dc_consonants = "âdrwvuzž"..jazm..""
function export.tr(text, lang, sc)
text = rsubn(text, " | ", "# | #")
text = "##" .. rsubn(text, " ", "# #") .. "##"
text = rsubn(text, "`", "")
text = rsubn(text, " ", "")
text = rsubn(text, ",", "] ,[")
text = rsubn(text, "%]", "#]#")
text = rsubn(text, "%[", "#[#")
-- remove unpronounced or incorrect letters
text = rsubn(text, "[.]", "")
text = rsubn(text, "v", "w")
text = rsubn(text, "iy", "ey")
text = rsubn(text, "(["..consonants.."])%1", "%1"..tashdid.."")
text = rsubn(text, "(["..consonants.."])(["..consonants.."])", "%1"..jazm.."%2")
text = rsubn(text, "(["..consonants.."])([-])", "%1"..jazm.."%2")
text = rsubn(text, "#â", "#آ")
text = rsubn(text, "'â", "آ")
text = rsubn(text, "([aeo])([-])", "%1h-")
text = rsubn(text, "(["..dc_consonants.."])([-])â", "%1آ")
text = rsubn(text, "([^"..dc_consonants.."])([-])â", "%1"..zwnj.."آ")
text = rsubn(text, "(["..dc_consonants.."])([-])(["..vowels.."])", "%1â%3")
text = rsubn(text, "([^"..dc_consonants.."])([-])(["..vowels.."])", "%1"..zwnj.."â%3")
text = rsubn(text, "(["..dc_consonants.."])([-])(["..consonants.."])", "%1%3")
text = rsubn(text, "([^"..dc_consonants.."])([-])(["..consonants.."])", "%1"..zwnj.."%3")
text = rsubn(text, "#(["..vowels.."])", "#â%1")
text = rsubn(text, "([aeo])#", "%1h#")
text = rsubn(text, "(['])#", "ء#")
text = mw.ustring.gsub(text, '.', convert_consonants)
text = mw.ustring.gsub(text, '.', convert_vowels)
text = rsubn(text, "[-]", "")
text = rsubn(text, "#", "")
return text
end
return export