Module:qlu-pron
- The following documentation is located at Module:qlu-pron/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module generates IPA pronunciation for Luthic words. Backend to {{qlu-IPA}}.
local sub = mw.ustring.sub
local find = mw.ustring.find
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local match = mw.ustring.match
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit
local lang = require("Module:languages").getByCode("qlu")
local m_table = require("Module:table")
local m_IPA = require("Module:IPA")
local export = {}
local consonants = "[mnɲŋptkbdɡɸfsθʃxβvzðɣʦʧʣʤlʎrɹɾʁʒʈʷʨʥḱːjw]"
local front = "ieɛɪæyʏøœ"
local back = "uoɔʊʌɑɒ"
local vowels = "[aɐ" .. front .. back .. "ːjw]"
local function laxen(v)
local otc = {}
local switch = {["e"] = "i", ["i"] = "ɪ", ["u"] = "ʊ"}
for vc in gmatch(v, ".") do
if switch[vc] then vc = gsub(vc, vc, switch[vc]) end
table.insert(otc, vc)
end
return table.concat(otc)
end
local function same(foo, bar)
foo, bar = mw.ustring.toNFD(foo), mw.ustring.toNFD(bar) -- decompose diacritics
foo, bar = match(foo, "^."), match(bar, "^.") -- sort out the letter
return foo == bar and true or false
end
local first_rules = {
{"sc([ei])", "ʃ%1"}, {"c([ei])", "ʧ%1"}, {"g([ei])", "ʤ%1"}, {"gu", "ǵ"}, {"%-", ""},
{"ch?", "k"}, {"g([cqg])", "ŋ%1"}, {"gli", "ʎi"}, {"gni", "ɲi"},
{"gh?", "ɡ"}, {"ph", "ɸ"}, {"th", "ʈ"}, {"h", ""},
{"qu?", "ḱ"}, {"z", "ʦ"}, {"þ", "θ"},
{"ae", "ɛ"}, {"au", "ɔ"}, {"ei", "i"},
}
local phonetic_rules = {
}
local last_rules = {
-- Escaped characters
{"ʤ", "d͡ʒ"}, {"ʧ", "t͡ʃ"}, {"ʦ", "t͡s"}, {"ʣ", "d͡z"},
{"ḱ", "kʷ"}, {"ǵ", "ɡʷ"}, {"ʈ", "t"},
}
local function syllabify(word)
word = gsub(word, "(" .. consonants .. "?" .. consonants .. "?" .. consonants .. "?" .. vowels .. "?" .. vowels .. vowels .. "?" .. consonants .. "?" .. consonants .. "?)", "·%1·")
local syllables = split(word, "·");
if #syllables ~= 1 then
for i, syll in ipairs(syllables) do
table.insert(syllables, #syllables-1, "ˈ")
return ret
end
local ret = table.concat(syllables, "·");
if not match(ret, "ˈ") then
syllables = split(ret, "·")
syllables[#syllables - 1] = "ˈ" .. syllables[#syllables - 1]
ret = table.concat(syllables, "·")
end
end
return table.concat(syllables, "·")
end
function export.crux(term)
term = mw.ustring.lower(term)
for _, rule in ipairs(first_rules) do
term = gsub(term, rule[1], rule[2])
end
term = syllabify(term)
--[[for _, rule in ipairs(phonetic_rules) do
term = gsub(term, rule[1], rule[2])
end]]
term = gsub(term, "·", ".")
term = gsub(term, "%.%.", ".")
for _, rule in ipairs(last_rules) do
term = gsub(term, rule[1], rule[2])
end
return term
end
function separate_word(term)
local result = {}
for word in gsplit(term, " ") do
table.insert(result, export.crux(word))
end
return table.concat(result, " ")
end
function export.show(frame)
local parent_args = frame:getParent().args
local params = {
[1] = { default = mw.title.getCurrentTitle().nsText == 'Template' and "aggiu" or mw.title.getCurrentTitle().text },
}
local args = require("Module:parameters").process(parent_args, params)
local term = args[1]
local IPA_args = {}
local phonetic = separate_word(term)
table.insert(IPA_args, {pron = '[' .. phonetic .. ']'})
return "* " .. m_IPA.format_IPA_full({lang = lang, items = IPA_args})
end
return export