Module:IPA: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
TheNightAvl (talk | contribs) No edit summary |
||
Line 11: | Line 11: | ||
[2] = {list = true}, | [2] = {list = true}, | ||
} | } | ||
function get_SAMPAd(ipa) | |||
local correspondences = { | |||
["g"] = "ɡ", | |||
[":"] = "ː", | |||
["'"] = "ˈ", | |||
} | |||
for from, to in pairs(correspondences) do | |||
ipa = mw.ustring.gsub(ipa, from, to) | |||
end | |||
return ipa | |||
end | |||
function format_ipa(language, ipa, nolarge, nopre, linked) | function format_ipa(language, ipa, nolarge, nopre, linked) | ||
Line 24: | Line 38: | ||
if i > 1 then out = out .. ", " end | if i > 1 then out = out .. ", " end | ||
out = out .. '<span class="' .. class .. '">' | out = out .. '<span class="' .. class .. '">' | ||
i_ipa = get_SAMPAd(i_ipa) | |||
if linked then | if linked then | ||
out = out .. "[[" .. language_pron .. "|" .. i_ipa .. "]]" | out = out .. "[[" .. language_pron .. "|" .. i_ipa .. "]]" |
Revision as of 17:04, 16 March 2024
{{IPA}}
local export = {}
local params = {
[1] = {},
[2] = {list = true},
nolarge = {type = "boolean"},
linked = {type = "boolean"},
nopre = {type = "boolean"},
}
local params_inline = {
[1] = {},
[2] = {list = true},
}
function get_SAMPAd(ipa)
local correspondences = {
["g"] = "ɡ",
[":"] = "ː",
["'"] = "ˈ",
}
for from, to in pairs(correspondences) do
ipa = mw.ustring.gsub(ipa, from, to)
end
return ipa
end
function format_ipa(language, ipa, nolarge, nopre, linked)
local language_pron = "Appendix:" .. language.name .. "_pronunciation"
local out = ""
if not nopre then
out = out .. "[[w:International_Phonetic_Alphabet|IPA]]"
out = out .. "<sup>([[" .. language_pron .. "|key]])</sup>: "
end
local class = "IPA"
if nolarge then class = class .. " nolarge" end
for i, i_ipa in ipairs(ipa) do
if i > 1 then out = out .. ", " end
out = out .. '<span class="' .. class .. '">'
i_ipa = get_SAMPAd(i_ipa)
if linked then
out = out .. "[[" .. language_pron .. "|" .. i_ipa .. "]]"
else
out = out .. i_ipa
end
out = out .. "</span>"
end
return out
end
function export.show(frame)
local args = require("Module:parameters").process(frame:getParent().args, params)
local language = require("Module:languages").get_by_code(args[1])
if language == nil then
error("No such language: " .. args[1])
end
return format_ipa(language, args[2], args["nolarge"], args["nopre"], args["linked"])
end
function export.show_inline(frame)
local args = require("Module:parameters").process(frame:getParent().args, params_inline)
local language = require("Module:languages").get_by_code(args[1])
if language == nil then
error("No such language: " .. args[1])
end
return format_ipa(language, args[2], true, true, true)
end
return export