Module:zm-pron
Jump to navigation
Jump to search
- The following documentation is located at Module:zm-pron/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
local sub = mw.ustring.sub
local find = mw.ustring.find
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local gsub = mw.ustring.gsub
local u = mw.ustring.char
local split = mw.text.split
local gsplit = mw.text.gsplit
-- To avoid weird annoying cursor behavior
local GRAVE = u(0x0300) -- COMBINING GRAVE ACCENT ̀◌
local ACUTE = u(0x0301) -- COMBINING ACUTE ACCENT
local SYLL = u(0x0329) -- COMBINING VERTICAL LINE BELOW ̩◌
local VL = u(0x0325) -- COMBINING RING BELOW ̥◌
local AFFR = u(0x0361) -- COMBINING DOUBLE INVERTED BREVE ͡
local back_vowel = "aouɔ"
local front_vowel = "ieɛ"
local vowels = "[" .. back_vowel .. front_vowel .. "]"
local acuted = "[áéíóú]"
local palatal = "[ʨjʎʃʒʥʤʧʦʣ]"
local sonorant = "[rl]"
local consonants = "[mnptkbdɡfvszxrljɲŋʋʎʨjʎʃʒʥʤʧʤʣʦʣ]"
local export = {}
local rules = {
{"ai", "ɛ"}, {"au", "ɔ"}, {"è", "ɛ"}, {"ò", "ɔ"},
{"dź", "ʥ"}, {"dž", "ʤ"}, {"c", "ʦ"}, {"ć", "ʨ"}, {"nj", "ɲ"}, {"č", "ʧ"}, {"ž", "ʒ"}, {"š", "ʃ"}, {"lj", "ʎ"},
{"h", "x"}, {"g", "ɡ"},
{"(" .. vowels .. ")[lv]$", "%1ʋ"}, {"(" .. acuted .. ")[lv]$", "%1ʋ"},
{"(" .. consonants ..")r(" .. consonants ..")", "%1(ə)r" .. SYLL .. "%2"}
,
{"(" .. palatal .. ")e", "%1ɛ"}, {"(" .. palatal .. ")é", "%1ɛ" .. ACUTE},
{"(" .. palatal .. ")o", "%1ɔ"}, {"(" .. palatal .. ")ó", "%1ɔ" .. ACUTE},
}
function export.crux(term)
term = mw.ustring.lower(term)
for _, rule in ipairs(rules) do
term = gsub(term, rule[1], rule[2])
end
return term
end
function IPA_span(items)
local bits = {}
for _, item in ipairs(items) do
local bit = "<span style=\"font-size:110%;font-family:'Gentium','DejaVu Sans','Segoe UI',sans-serif>" .. item.pron .. "</span>"
table.insert(bits, bit)
end
return table.concat(bits)
end
function format_IPA(items)
return "[[w:IPA chart|IPA]]<sup>([[IPA for Zemljask|key]])</sup>: " .. IPA_span(items)
end
function line_format(pronunciation, register)
local full_pronunciations = {}
local IPA_args = {{pron = '[' .. pronunciation .. ']'}}
table.insert(full_pronunciations, format_IPA(IPA_args))
return "(''" .. table.concat(register, ", ") .. "'')" .. ' ' .. table.concat(full_pronunciations, ' or ')
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 params = {
[1] = { default = mw.title.getCurrentTitle().nsText == 'Template' and "dźelo" or mw.title.getCurrentTitle().text },
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local term = args[1]
local ipa = "* "
ipa = ipa .. line_format(separate_word(term), {'Standard'})
return ipa
end
return export