![]() | We're back! Sorry, bad combo of sickness, funeral and a month-long trip abroad. The site is back now. ![]() |
Module:IPA: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
local | local m_IPA = require("Module:IPA") | ||
local parameter_utilities_module = "Module:parameter utilities" | |||
-- Used for [[Template:IPA]]. | |||
function export.IPA(frame) | |||
local | local parent_args = frame:getParent().args | ||
local | local include_langname = frame.args.include_langname | ||
local | local compat = parent_args.lang | ||
local offset = compat and 0 or 1 | |||
local | local lang_arg = compat and "lang" or 1 | ||
local | |||
local | local params = { | ||
[lang_arg] = {required = true, type = "language", default = "en"}, | |||
[1 + offset] = {list = true, disallow_holes = true}, | |||
-- Deprecated; don't use in new code. | |||
["qual"] = {list = true, allow_holes = true, separate_no_index = true, alias_of = "q"}, | |||
["nocount"] = {type = "boolean"}, | |||
["nocat"] = {type = "boolean"}, | |||
["sort"] = {}, | |||
} | |||
local | local m_param_utils = require(parameter_utilities_module) | ||
local | 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 | local lang = args[lang_arg] | ||
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 | end | ||
-- Used for [[Template:IPAchar]]. | |||
local | function export.IPAchar(frame) | ||
local parent_args = frame.getParent and frame:getParent().args or frame | |||
local | local params = { | ||
[1] = {list = true, disallow_holes = true}, | |||
-- FIXME, remove this. | |||
["lang"] = {}, -- This parameter is not used and does nothing, but is allowed for futureproofing. | |||
} | |||
local m_param_utils = require(parameter_utilities_module) | |||
local | 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", | |||
} | |||
-- Format | |||
return m_IPA.format_IPA_multiple(nil, items) | |||
end | |||
function export.XSAMPA(frame) | |||
local params = { | |||
[1] = { required = true }, | |||
} | |||
local args = require("Module:parameters").process(frame:getParent().args, params) | |||
return m_IPA.XSAMPA_to_IPA(args[1] or "[Eg'zA:mp5=]") | |||
return | |||
end | end | ||
-- Used by [[Template:X2IPA]] | |||
function export.X2IPAtemplate(frame) | |||
local parent_args = frame.getParent and frame:getParent().args or frame | |||
local compat = parent_args["lang"] | |||
local offset = compat and 0 or 1 | |||
local params = { | |||
[compat and "lang" or 1] = {required = true, default = "und"}, | |||
[1 + offset] = {list = true, allow_holes = true}, | |||
{ | ["ref"] = {list = true, allow_holes = true}, | ||
["a"] = {list = true, allow_holes = true, separate_no_index = true}, | |||
["aa"] = {list = true, allow_holes = true, separate_no_index = true}, | |||
["q"] = {list = true, allow_holes = true, separate_no_index = true}, | |||
["qq"] = {list = true, allow_holes = true, separate_no_index = true}, | |||
["qual"] = {list = true, allow_holes = true}, | |||
["nocount"] = {type = "boolean"}, | |||
["sort"] = {}, | |||
} | |||
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[1 + offset], args.ref, args.a, args.aa, args.q, args.qq, args.qual, args[compat and "lang" or 1] | |||
local output = {} | |||
table.insert(output, "{{IPA") | |||
table.insert(output, "|" .. lang) | |||
if a.default then | |||
if | table.insert(output, "|a=" .. a.default) | ||
end | |||
if q.default then | |||
table.insert(output, "|q=" .. q.default) | |||
end | end | ||
for i = 1, math.max(pronunciations.maxindex, refs.maxindex, a.maxindex, aa.maxindex, q.maxindex, qq.maxindex, | |||
qual.maxindex) do | |||
if pronunciations[i] then | |||
for i, | table.insert(output, "|" .. m_XSAMPA.XSAMPA_to_IPA(pronunciations[i])) | ||
if | |||
end | end | ||
if a[i] then | |||
if | table.insert(output, "|a" .. i .. "=" .. a[i]) | ||
end | end | ||
if aa[i] then | |||
if | table.insert(output, "|aa" .. i .. "=" .. aa[i]) | ||
end | end | ||
if q[i] then | |||
table.insert(output, "|q" .. i .. "=" .. q[i]) | |||
end | end | ||
if qq[i] then | |||
if | table.insert(output, "|qq" .. i .. "=" .. qq[i]) | ||
end | end | ||
if | if refs[i] then | ||
table.insert(output, "|ref" .. i .. "=" .. refs[i]) | |||
end | end | ||
if qual[i] then | |||
table.insert(output, "|qual" .. i .. "=" .. qual[i]) | |||
if | |||
end | end | ||
end | end | ||
if aa.default then | |||
table.insert(output, "|aa=" .. aa.default) | |||
end | |||
if qq.default then | |||
table.insert(output, "|qq=" .. qq.default) | |||
if | |||
end | end | ||
if args.nocount then | |||
table.insert(output, "|nocount=1") | |||
if | |||
end | end | ||
if args.sort then | |||
if | table.insert(output, "|sort=" .. args.sort) | ||
insert( | |||
end | end | ||
table.insert(output, "}}") | |||
return table.concat(output) | |||
end | |||
-- Used by [[Template:X2IPAchar]] | |||
function export.X2IPAchar(frame) | |||
local params = { | |||
[1] = { list = true, allow_holes = true }, | |||
["ref"] = {list = true, allow_holes = true}, | |||
["q"] = {list = true, allow_holes = true, require_index = true}, | |||
["qq"] = {list = true, allow_holes = true, require_index = true}, | |||
["qual"] = { list = true, allow_holes = true }, | |||
-- FIXME, remove this. | |||
["lang"] = {}, | |||
} | |||
local args = require("Module:parameters").process(frame:getParent().args, params) | |||
- | local m_XSAMPA = require("Module:IPA/X-SAMPA") | ||
local pronunciations, refs, q, qq, qual, lang = args[1], 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[i] then | |||
local | table.insert(output, "|" .. m_XSAMPA.XSAMPA_to_IPA(pronunciations[i])) | ||
if | |||
end | end | ||
if q[i] then | |||
table.insert(output, "|q" .. i .. "=" .. q[i]) | |||
end | end | ||
if | if qq[i] then | ||
table.insert(output, "|qq" .. i .. "=" .. qq[i]) | |||
end | end | ||
if qual[i] then | |||
table.insert(output, "|qual" .. i .. "=" .. qual[i]) | |||
end | end | ||
if refs[i] then | |||
table.insert(output, "|ref" .. i .. "=" .. refs[i]) | |||
end | end | ||
end | end | ||
if | if lang then | ||
insert( | table.insert(output, "|lang=" .. lang) | ||
end | end | ||
table.insert(output, "}}") | |||
return table.concat(output) | |||
end | |||
-- Used by [[Template:x2rhymes]] | |||
function export.X2rhymes(frame) | |||
local parent_args = frame.getParent and frame:getParent().args or frame | |||
local compat = parent_args["lang"] | |||
local offset = compat and 0 or 1 | |||
local params = { | |||
[compat and "lang" or 1] = {required = true, default = "und"}, | |||
[1 + offset] = {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[1 + offset], args[compat and "lang" or 1] | |||
local output = {} | |||
table.insert(output, "{{rhymes") | |||
table.insert(output, "|" .. lang) | |||
for i = 1, pronunciations.maxindex do | |||
if pronunciations[i] then | |||
table.insert(output, "|" .. m_XSAMPA.XSAMPA_to_IPA(pronunciations[i])) | |||
end | end | ||
end | end | ||
table.insert(output, "}}") | |||
return table.concat(output) | |||
return | |||
end | end | ||
-- | -- Used for [[Template:enPR]]. | ||
function export.enPR(frame) | |||
local parent_args = frame:getParent().args | |||
function export. | |||
local | |||
local params = { | |||
[1] = {list = true, disallow_holes = true}, | |||
} | |||
local | 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, | |||
} | |||
local | |||
return | return m_IPA.format_enPR_full(data) | ||
end | end | ||
return export | return export |
Revision as of 10:25, 8 January 2025
- The following documentation is located at Module:IPA/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
local export = {}
local m_IPA = require("Module:IPA")
local parameter_utilities_module = "Module:parameter utilities"
-- Used for [[Template:IPA]].
function export.IPA(frame)
local parent_args = frame:getParent().args
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 = {
[lang_arg] = {required = true, type = "language", default = "en"},
[1 + offset] = {list = true, disallow_holes = true},
-- Deprecated; don't use in new code.
["qual"] = {list = true, allow_holes = true, separate_no_index = true, alias_of = "q"},
["nocount"] = {type = "boolean"},
["nocat"] = {type = "boolean"},
["sort"] = {},
}
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[lang_arg]
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 [[Template:IPAchar]].
function export.IPAchar(frame)
local parent_args = frame.getParent and frame:getParent().args or frame
local params = {
[1] = {list = true, disallow_holes = true},
-- FIXME, remove this.
["lang"] = {}, -- 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",
}
-- Format
return m_IPA.format_IPA_multiple(nil, items)
end
function export.XSAMPA(frame)
local params = {
[1] = { required = true },
}
local args = require("Module:parameters").process(frame:getParent().args, params)
return m_IPA.XSAMPA_to_IPA(args[1] or "[Eg'zA:mp5=]")
end
-- Used by [[Template:X2IPA]]
function export.X2IPAtemplate(frame)
local parent_args = frame.getParent and frame:getParent().args or frame
local compat = parent_args["lang"]
local offset = compat and 0 or 1
local params = {
[compat and "lang" or 1] = {required = true, default = "und"},
[1 + offset] = {list = true, allow_holes = true},
["ref"] = {list = true, allow_holes = true},
["a"] = {list = true, allow_holes = true, separate_no_index = true},
["aa"] = {list = true, allow_holes = true, separate_no_index = true},
["q"] = {list = true, allow_holes = true, separate_no_index = true},
["qq"] = {list = true, allow_holes = true, separate_no_index = true},
["qual"] = {list = true, allow_holes = true},
["nocount"] = {type = "boolean"},
["sort"] = {},
}
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[1 + offset], args.ref, args.a, args.aa, args.q, args.qq, args.qual, args[compat and "lang" or 1]
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[i] then
table.insert(output, "|" .. m_XSAMPA.XSAMPA_to_IPA(pronunciations[i]))
end
if a[i] then
table.insert(output, "|a" .. i .. "=" .. a[i])
end
if aa[i] then
table.insert(output, "|aa" .. i .. "=" .. aa[i])
end
if q[i] then
table.insert(output, "|q" .. i .. "=" .. q[i])
end
if qq[i] then
table.insert(output, "|qq" .. i .. "=" .. qq[i])
end
if refs[i] then
table.insert(output, "|ref" .. i .. "=" .. refs[i])
end
if qual[i] then
table.insert(output, "|qual" .. i .. "=" .. qual[i])
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 [[Template:X2IPAchar]]
function export.X2IPAchar(frame)
local params = {
[1] = { list = true, allow_holes = true },
["ref"] = {list = true, allow_holes = true},
["q"] = {list = true, allow_holes = true, require_index = true},
["qq"] = {list = true, allow_holes = true, require_index = true},
["qual"] = { list = true, allow_holes = true },
-- FIXME, remove this.
["lang"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local m_XSAMPA = require("Module:IPA/X-SAMPA")
local pronunciations, refs, q, qq, qual, lang = args[1], 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[i] then
table.insert(output, "|" .. m_XSAMPA.XSAMPA_to_IPA(pronunciations[i]))
end
if q[i] then
table.insert(output, "|q" .. i .. "=" .. q[i])
end
if qq[i] then
table.insert(output, "|qq" .. i .. "=" .. qq[i])
end
if qual[i] then
table.insert(output, "|qual" .. i .. "=" .. qual[i])
end
if refs[i] then
table.insert(output, "|ref" .. i .. "=" .. refs[i])
end
end
if lang then
table.insert(output, "|lang=" .. lang)
end
table.insert(output, "}}")
return table.concat(output)
end
-- Used by [[Template:x2rhymes]]
function export.X2rhymes(frame)
local parent_args = frame.getParent and frame:getParent().args or frame
local compat = parent_args["lang"]
local offset = compat and 0 or 1
local params = {
[compat and "lang" or 1] = {required = true, default = "und"},
[1 + offset] = {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[1 + offset], args[compat and "lang" or 1]
local output = {}
table.insert(output, "{{rhymes")
table.insert(output, "|" .. lang)
for i = 1, pronunciations.maxindex do
if pronunciations[i] then
table.insert(output, "|" .. m_XSAMPA.XSAMPA_to_IPA(pronunciations[i]))
end
end
table.insert(output, "}}")
return table.concat(output)
end
-- Used for [[Template:enPR]].
function export.enPR(frame)
local parent_args = frame:getParent().args
local params = {
[1] = {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