Module:accent qualifier: Difference between revisions

From Linguifex
Jump to navigation Jump to search
(Created page with "local export = {} local m_qualifier = require("Module:qualifier") function export.format_qualifiers(qualifiers) local m_data = mw.loadData("Module:accent qualifier/data")...")
 
No edit summary
 
Line 1: Line 1:
local export = {}
local export = {}
local m_qualifier = require("Module:qualifier")


function export.format_qualifiers(qualifiers)
local labels_module = "Module:labels"
local m_data = mw.loadData("Module:accent qualifier/data")
 
--[==[
if type(qualifiers) ~= "table" then
Format accent qualifiers. Implements the {{tl|a}} (shortcut for {{tl|accent}}) template. This template is now virtually
qualifiers = { qualifiers }
identical to a non-categorizing {{tl|lb}}, although a few labels display and/or link differently (e.g. Egyptian-language
end
label 'Old Egyptian' displays as "reconstructed Old Egyptian" instead of just "Old Egyptian", and English-language
label 'Australia' displays as "General Australian" instead of just "Australia", and links to
local accents = {}
[[w:Australian English phonology]] instead of [[w:Australian English]]).
local categories = {}
]==]
function export.format_qualifiers(lang, qualifiers)
for _, accent in ipairs(qualifiers) do
return require(labels_module).show_labels {
local data
lang = lang,
labels = qualifiers,
-- Replace an alias with the label that has a data table.
nocat = true,
if m_data.aliases[accent] then
mode = "accent",
accent = m_data.aliases[accent]
}
end
-- Retrieve the label's data table.
if m_data.labels[accent] then
data = m_data.labels[accent]
end
-- Use the link and displayed text in the data table, if they exist.
if data then
if data.link then
table.insert(accents, "[[w:" .. data.link .. "|" ..
(data.display or data.link) .. "]]")
elseif data.display then
table.insert(accents, data.display)
end
--[[
if data[accent] then
if data[accent].type == "sound change" then
table.insert(categories, lang:getCanonicalName() .. " terms with pronunciations exhibiting " .. accent)
end
end
]]
else
table.insert(accents, accent)
end
end
return m_qualifier.format_qualifier(accents)
end
end


-- Called by {{accent}} or {{a}}.
--[==[
External entry point that implements {{tl|accent}} and {{tl|a}}.
]==]
function export.show(frame)
function export.show(frame)
local args = frame.getParent and frame:getParent().args or frame
if not frame.getParent then
error("When calling [[Module:accent qualifier]] internally, use format_qualifiers() not show()")
if (not args[1] or args[1] == "") and mw.title.getCurrentTitle().nsText == "Template" then
return m_qualifier.format_qualifier{ '{{{1}}}' }
end
end
local parent_args = frame:getParent().args
 
local params = {
local params = {
[1] = {required = true, list = true}
[1] = {type = "language", default = "und"},
[2] = {list = true, required = true, default = "{{{2}}}"},
}
}
args = require("Module:parameters").process(args, params)
local args = require("Module:parameters").process(parent_args, params)
return export.format_qualifiers(args[1], args[2])
return export.format_qualifiers(args[1])
end
end


return export
return export

Latest revision as of 13:43, 26 January 2025



local export = {}

local labels_module = "Module:labels"

--[==[
Format accent qualifiers. Implements the {{tl|a}} (shortcut for {{tl|accent}}) template. This template is now virtually
identical to a non-categorizing {{tl|lb}}, although a few labels display and/or link differently (e.g. Egyptian-language
label 'Old Egyptian' displays as "reconstructed Old Egyptian" instead of just "Old Egyptian", and English-language
label 'Australia' displays as "General Australian" instead of just "Australia", and links to
[[w:Australian English phonology]] instead of [[w:Australian English]]).
]==]
function export.format_qualifiers(lang, qualifiers)
	return require(labels_module).show_labels {
		lang = lang,
		labels = qualifiers,
		nocat = true,
		mode = "accent",
	}
end

--[==[
External entry point that implements {{tl|accent}} and {{tl|a}}.
]==]
function export.show(frame)
	if not frame.getParent then
		error("When calling [[Module:accent qualifier]] internally, use format_qualifiers() not show()")
	end
	local parent_args = frame:getParent().args

	local params = {
		[1] = {type = "language", default = "und"},
		[2] = {list = true, required = true, default = "{{{2}}}"},
	}
	local args = require("Module:parameters").process(parent_args, params)
	return export.format_qualifiers(args[1], args[2])
end

return export