This module is used by {{IPA}}
, {{IPAchar}}
, {{x2i}}
, {{x2ipa}}
, {{x2ipachar}}
, {{x2rhymes}}
.
Because {{IPA}}
always includes a language code, you can track when certain symbols or sequences of symbols are used in a particular language's IPA transcriptions. This allows you to find and correct incorrect transcriptions. The tracking function is found in Module:IPA/tracking.
local export = {}
local m_IPA = require("Module:IPA")
local parameter_utilities_module = "Module:parameter utilities"
local function track(template, page)
require("Module:debug/track")(template .. "/" .. page)
return true
end
-- Used for ].
function export.IPA(frame)
local parent_args = frame:getParent().args
-- Track uses of n so they can be converted to ref.
-- Track uses of qual so they can be converted to q.
for k, v in pairs(parent_args) do
if type(k) == "string" and k:find("^qual*$") then
track("IPA", "q")
end
end
local include_langname = frame.args.include_langname
local compat = parent_args.lang
local offset = compat and 0 or 1
local lang_arg = compat and "lang" or 1
local params = {
= {required = true, type = "language", default = "en"},
= {list = true, disallow_holes = true},
-- Deprecated; don't use in new code.
= {list = true, allow_holes = true, separate_no_index = true, alias_of = "q"},
= {type = "boolean"},
= {type = "boolean"},
= {},
}
local m_param_utils = require(parameter_utilities_module)
local param_mods = m_param_utils.construct_param_mods {
{group = {"ref", "a", "q"}},
{group = "link", include = {"t", "gloss", "pos"}},
}
local items, args = m_param_utils.process_list_arguments {
params = params,
param_mods = param_mods,
raw_args = parent_args,
termarg = 1 + offset,
term_dest = "pron",
track_module = "IPA",
}
local lang = args
for _, item in ipairs(items) do
require("Module:IPA/tracking").run_tracking(item.pron, lang)
end
local data = {
lang = lang,
items = items,
no_count = args.nocount,
nocat = args.nocat,
sort_key = args.sort,
include_langname = include_langname,
q = args.q.default,
qq = args.qq.default,
a = args.a.default,
aa = args.aa.default,
}
return m_IPA.format_IPA_full(data)
end
-- Used for ].
function export.IPAchar(frame)
local parent_args = frame.getParent and frame:getParent().args or frame
-- Track uses of n so they can be converted to ref.
-- Track uses of qual so they can be converted to q.
for k, v in pairs(parent_args) do
if type(k) == "string" and k:find("^n*$") then
track("IPAchar", "n")
end
if type(k) == "string" and k:find("^qual*$") then
track("IPAchar", "q")
end
end
local params = {
= {list = true, disallow_holes = true},
-- FIXME, remove this.
= {}, -- This parameter is not used and does nothing, but is allowed for futureproofing.
}
local m_param_utils = require(parameter_utilities_module)
local param_mods = m_param_utils.construct_param_mods {
-- It doesn't really make sense to have separate overall a=/aa=/q=/qq= for {{IPAchar}}, which doesn't format a
-- whole line but just individual pronunciations. Instead they are associated with the first item.
{group = {"ref", "a", "q"}, separate_no_index = false},
-- Deprecated; don't use in new code.
{param = "qual", alias_of = "q"},
}
local items, args = m_param_utils.process_list_arguments {
params = params,
param_mods = param_mods,
raw_args = parent_args,
termarg = 1,
term_dest = "pron",
track_module = "IPAchar",
}
-- ]
if args.lang then
track("IPAchar", "lang")
end
-- Format
return m_IPA.format_IPA_multiple(nil, items)
end
function export.XSAMPA(frame)
local params = {
= { required = true },
}
local args = require("Module:parameters").process(frame:getParent().args, params)
return m_IPA.XSAMPA_to_IPA(args or "")
end
-- Used by ]
function export.X2IPAtemplate(frame)
local parent_args = frame.getParent and frame:getParent().args or frame
local compat = parent_args
local offset = compat and 0 or 1
local params = {
= {required = true, default = "und"},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true},
= {list = true, allow_holes = true, separate_no_index = true},
= {list = true, allow_holes = true, separate_no_index = true},
= {list = true, allow_holes = true, separate_no_index = true},
= {list = true, allow_holes = true, separate_no_index = true},
= {list = true, allow_holes = true},
= {type = "boolean"},
= {},
}
local args = require("Module:parameters").process(parent_args, params)
local m_XSAMPA = require("Module:IPA/X-SAMPA")
local pronunciations, refs, a, aa, q, qq, qual, lang =
args, args.ref, args.a, args.aa, args.q, args.qq, args.qual, args
local output = {}
table.insert(output, "{{IPA")
table.insert(output, "|" .. lang)
if a.default then
table.insert(output, "|a=" .. a.default)
end
if q.default then
table.insert(output, "|q=" .. q.default)
end
for i = 1, math.max(pronunciations.maxindex, refs.maxindex, a.maxindex, aa.maxindex, q.maxindex, qq.maxindex,
qual.maxindex) do
if pronunciations then
table.insert(output, "|" .. m_XSAMPA.XSAMPA_to_IPA(pronunciations))
end
if a then
table.insert(output, "|a" .. i .. "=" .. a)
end
if aa then
table.insert(output, "|aa" .. i .. "=" .. aa)
end
if q then
table.insert(output, "|q" .. i .. "=" .. q)
end
if qq then
table.insert(output, "|qq" .. i .. "=" .. qq)
end
if refs then
table.insert(output, "|ref" .. i .. "=" .. refs)
end
if qual then
table.insert(output, "|qual" .. i .. "=" .. qual)
end
end
if aa.default then
table.insert(output, "|aa=" .. aa.default)
end
if qq.default then
table.insert(output, "|qq=" .. qq.default)
end
if args.nocount then
table.insert(output, "|nocount=1")
end
if args.sort then
table.insert(output, "|sort=" .. args.sort)
end
table.insert(output, "}}")
return table.concat(output)
end
-- Used by ]
function export.X2IPAchar(frame)
local params = {
= { list = true, allow_holes = true },
= {list = true, allow_holes = true},
= {list = true, allow_holes = true, require_index = true},
= {list = true, allow_holes = true, require_index = true},
= { list = true, allow_holes = true },
-- FIXME, remove this.
= {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
-- ]
if args.lang then
track("X2IPAchar", "lang")
end
local m_XSAMPA = require("Module:IPA/X-SAMPA")
local pronunciations, refs, q, qq, qual, lang = args, args.ref, args.q, args.qq, args.qual, args.lang
local output = {}
table.insert(output, "{{IPAchar")
for i = 1, math.max(pronunciations.maxindex, refs.maxindex, q.maxindex, qq.maxindex, qual.maxindex) do
if pronunciations then
table.insert(output, "|" .. m_XSAMPA.XSAMPA_to_IPA(pronunciations))
end
if q then
table.insert(output, "|q" .. i .. "=" .. q)
end
if qq then
table.insert(output, "|qq" .. i .. "=" .. qq)
end
if qual then
table.insert(output, "|qual" .. i .. "=" .. qual)
end
if refs then
table.insert(output, "|ref" .. i .. "=" .. refs)
end
end
if lang then
table.insert(output, "|lang=" .. lang)
end
table.insert(output, "}}")
return table.concat(output)
end
-- Used by ]
function export.X2rhymes(frame)
local parent_args = frame.getParent and frame:getParent().args or frame
local compat = parent_args
local offset = compat and 0 or 1
local params = {
= {required = true, default = "und"},
= {required = true, list = true, allow_holes = true},
}
local args = require("Module:parameters").process(parent_args, params)
local m_XSAMPA = require("Module:IPA/X-SAMPA")
pronunciations, lang = args, args
local output = {}
table.insert(output, "{{rhymes")
table.insert(output, "|" .. lang)
for i = 1, pronunciations.maxindex do
if pronunciations then
table.insert(output, "|" .. m_XSAMPA.XSAMPA_to_IPA(pronunciations))
end
end
table.insert(output, "}}")
return table.concat(output)
end
-- Used for ].
function export.enPR(frame)
local parent_args = frame:getParent().args
local params = {
= {list = true, disallow_holes = true},
}
local m_param_utils = require(parameter_utilities_module)
local param_mods = m_param_utils.construct_param_mods {
{group = {"q", "a", "ref"}},
}
local items, args = m_param_utils.process_list_arguments {
params = params,
param_mods = param_mods,
raw_args = parent_args,
termarg = 1,
term_dest = "pron",
track_module = "enPR",
}
local data = {
items = items,
q = args.q.default,
qq = args.qq.default,
a = args.a.default,
aa = args.aa.default,
}
return m_IPA.format_enPR_full(data)
end
return export