Module:User:AmazingJus/so

local export = {}

local m_IPA = require("Module:IPA") local lang = require("Module:languages").getByCode("so") local sc = require("Module:scripts").getByCode("Latn") local hyphen = require("Module:hyphenation") local table = require("Module:table")

function export.tag_text(text, face) return require("Module:script utilities").tag_text(text, lang, sc, face) end

function export.link(term, face) return require("Module:links").full_link( { term = term, lang = lang, sc = sc }, face ) end

local U = mw.ustring.char local decomp = mw.ustring.toNFD local find = mw.ustring.find local gsub = mw.ustring.gsub local lower = mw.ustring.lower local strip = mw.text.trim

local acute = U(0x301) local grave = U(0x300) local circumflex = U(0x302) local semibreve = U(0x32F) local tones = "[" .. acute .. grave .. "]"

local cons = { ["j"] = "d͡ʒ", ["x"] = "ħ", ["kh"] = "ħ", ["sh"] = "ʃ", ["dh"] = "ɖ", ["c"] = "ʕ", ["g"] = "ɡ", ["y"] = "j", ["'"] = "ʔ" }

-- order of vowels: front, back local vowels = { ["a"] = { "æ", "ɑ" }, ["e"] = { "e", "ɛ" }, ["i"] = { "i", "ɪ" }, ["o"] = { "ɵ", "ɔ" }, ["u"] = { "ʉ", "u" } }

function export.toIPA(term, front) if type(term) == "table" then term = term.args[1] end

-- make all term lowercase and word borders have a space term = lower(term) term = " " .. term .. " "

-- decompose tone accents where entries must have tones marked term = decomp(term) if not find(term, tones) then error("Entry does not have a tone mark.") end

term = gsub(term, "([aeo])w([aeiou^]?)(w?)", "%1u" .. semibreve .. "%2%3") term = gsub(term, "([ao])y([aeiou^]?)(y?)", "%1i" .. semibreve .. "%2%3") term = gsub(term, "([a-z])%1(h?)", "%1%2ː") term = gsub(term, " ([aeiou])", " ʔ%1")

-- assign consonant values term = gsub(term, "[a-z]h?", cons)

-- assign appropriate values for vowels if front then term = gsub(term, "[aeiou]", function(vowel)			return vowels[vowel][1]		end) else term = gsub(term, "[aeiou]", function(vowel)			return vowels[vowel][2]		end) end

-- grave accent is falling tone term = gsub(term, grave, circumflex)

return strip(term) end

return export