Jump to content

Module:IPA/category documentation: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
No edit summary
Line 42: Line 42:
end
end
end
end
end
if not code and args.container ~= 'yes' then
return frame:expandTemplate({ title = 'Hidden category' }) .. string.format('<span class="error" style="font-size: 100%%; font-style: normal;">Error: language code for "%s" not found. Please see [[Template talk:IPA]] for assistance.</span>[[Category:IPA template errors]]', name)
end
end
local isCollective = name:find(' languages$') and true
local isCollective = name:find(' languages$') and true
Line 48: Line 51:
isCollective and name or
isCollective and name or
name .. ' language'
name .. ' language'
if not mw.title.new(link).exists then
link = mLang._name_from_tag({ code, link = 'yes' })
:match('^%[%[([^|%]]+)')
end
local key = lect and lect.key or parent and parent.key
local key = lect and lect.key or parent and parent.key
local langCat, langCatCount
local langCat, langCatCount
Line 74: Line 81:
name
name
local ret = {}
local ret = {}
table.insert(ret, frame:expandTemplate{title = 'Tracking category'})
table.insert(ret, frame:expandTemplate({ title = 'Tracking category' }))
table.insert(ret,
table.insert(ret, string.format(
'The following pages contain [[International Phonetic Alphabet|IPA]] transcriptions of [[%s|%s]] using %s. This category should never be added manually.',
string.format(
link,
'The following pages contain [[International Phonetic Alphabet|IPA]] transcriptions of [[%s|%s]] using %s. This category should never be added manually.',
link,
name,
name,
code
and string.format('<code>{{[[Template:IPA|IPA]]|%s|...}}</code>', code)
code
and string.format('<code>{{[[Template:IPA|IPA]]|%s|...}}</code>', code)
or '[[Template:IPA]]'
))
or '[[Template:IPA]]'
)
)
if key then
if key then
table.insert(ret, string.format(
table.insert(ret, string.format(
Line 97: Line 102:
code and ' (' .. code .. ')' or ''
code and ' (' .. code .. ')' or ''
))
))
end
if not code and args.container ~= 'yes' then
local layout = {}
table.insert(layout, frame:expandTemplate{title = 'Hidden category'})
local error_message = string.format('language code for "%s" not found. Please see [[Template talk:IPA]] for assistance.', name)
table.insert(layout, string.format('<span style="font-size: 100%%; font-style: normal;" class="error">Error: %s</span>', error_message))
table.insert(layout, "[[Category:IPA template errors]]")
return table.concat(layout)
end
end
if args.content then
if args.content then

Revision as of 10:47, 27 December 2024

require('strict')

local p = {}
local lects = mw.loadData('Module:IPA/data/export')
local mLang = require('Module:Lang')

function p.main(frame)
	local args = {}
	for k, v in pairs(frame:getParent().args) do
		if v ~= '' then
			args[k] = v
		end
	end
	local name = mw.title.getCurrentTitle().text:sub(12, -5)
	local lect, parent
	local code = args.code
	if not code then
		for _, lect2 in ipairs(lects) do
			if (lect2.name or lect2.extName) == name then
				lect = lect2
				parent = lect.parent
				code = lect.code
				break
			end
		end
	end
	if not code then
		code = mLang._tag_from_name({ name })
		if code:find('^<span') then
			code = nil
		else
			local regionCode = code:match('-(.+)')
			if regionCode and regionCode:sub(1, 2) ~= 'x-' then
				code = code:sub(1, #code - #regionCode) .. regionCode:upper()
			end
			for _, lect2 in ipairs(lects) do
				if lect2.code == code then
					lect = lect2
					parent = lect.parent
					break
				end
			end
		end
	end
	if not code and args.container ~= 'yes' then
		return frame:expandTemplate({ title = 'Hidden category' }) .. string.format('<span class="error" style="font-size: 100%%; font-style: normal;">Error: language code for "%s" not found. Please see [[Template talk:IPA]] for assistance.</span>[[Category:IPA template errors]]', name)
	end
	local isCollective = name:find(' languages$') and true
	local link = lect and (lect.link or lect.generatedLink or lect.extLink) or
		parent and (parent.link or parent.generatedLink or parent.extLink) or
		isCollective and name or
		name .. ' language'
	if not mw.title.new(link).exists then
		link = mLang._name_from_tag({ code, link = 'yes' })
			:match('^%[%[([^|%]]+)')
	end
	local key = lect and lect.key or parent and parent.key
	local langCat, langCatCount
	if code then
		langCat = mLang._category_from_tag({ code })
		if langCat:find('^<span') then
			langCat = nil
		else
			langCatCount = mw.site.stats.pagesInCategory(langCat:sub(10), 'pages')
		end
	end
	local parentName = args.parent or
		parent and (parent.name or parent.extName) or
		code and code:find('-') and mLang._name_from_tag({ code:gsub('%-.*', '') })
	if parentName == name or
		parentName and parentName:find('^<span')
	then
		parentName = nil
	end
	local cat = args.cat ~= 'no' and (
		parentName and 'Pages with ' .. parentName .. ' IPA' or
			'Pages with IPA'
	)
	local sortkey = args.sort or
		name:find('^[ %l]+$') and ' ' .. name or
		name
	local ret = {}
	table.insert(ret, frame:expandTemplate({ title = 'Tracking category' }))
	table.insert(ret, string.format(
		'The following pages contain [[International Phonetic Alphabet|IPA]] transcriptions of [[%s|%s]] using %s. This category should never be added manually.',
		link,
		name,
		code
			and string.format('<code>{{[[Template:IPA|IPA]]|%s|...}}</code>', code)
			or '[[Template:IPA]]'
	))
	if key then
		table.insert(ret, string.format(
			'By default, the transcriptions are linked to the [[%s]] key. Transcriptions that do not adhere to the conventions of the key must have <code>|generic=yes</code>.',
			key
		))
	end
	if isCollective then
		table.insert(ret, string.format(
			'The %s are a language collective. Please replace the code%s with those of more specific languages where possible.',
			name,
			code and ' (' .. code .. ')' or ''
		))
	end
	if args.content then
		table.insert(ret, args.content)
	end
	if langCat and langCatCount ~= 0 then
		table.insert(ret, string.format(
			'==See also==\n*[[:%s]] (%s)',
			langCat,
			mw.language.new('en'):formatNum(langCatCount)
		))
	end
	if cat then
		table.insert(ret, string.format('[[Category:%s|%s]]', cat, sortkey))
	end
	return table.concat(ret, '\n\n')
end

return p