跳转到内容

模組:IPA/category documentation

维基百科,自由的百科全书

这是Module:IPA/category documentation当前版本,由Kcx36留言 | 贡献编辑于2025年12月15日 (一) 12:56。这个网址是本页该版本的固定链接。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
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:match('^含有(.+)國際音標的頁面$')
	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;">错误:找不到“%s”的语言代码。请参阅[[Template talk:IPA]]获取帮助。</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 .. '语'
	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 mLang._name_from_tag({ parent.code, raw = 'yes' }))
		or code and code:find('-') and mLang._name_from_tag({ code:gsub('%-.*', ''), raw = 'yes' })
	if parentName == name or parentName and parentName:find('^<span') then
		parentName = nil
	end
	local cat = args.cat ~= 'no' and (
		parentName and '含有' .. parentName .. '國際音標的頁面' or '含有国际音标的页面'
	)
	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(
		'本分类收录使用%s为[[%s|%s]]标注[[国际音标]]的页面。本分类不应手动添加。',
		code
			and string.format('<code>{{[[Template:IPA|IPA]]|%s|...}}</code>', code)
			or '[[Template:IPA]]',
		link,
		name
	))
	if key then
		table.insert(ret, string.format(
			'默认情况下,音标会链接到[[%s]]发音指南。不符合该指南约定的音标必须添加<code>|generic=yes</code>参数。',
			key
		))
	end
	if isCollective or args.collective == 'yes' then
		table.insert(ret, string.format(
			'%s是语言集合。请尽可能使用更具体的语言代码%s代替。',
			isCollective and string.format('The %s are', name) or string.format('%s is', 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(
			'==参见==\n*[[:%s]](%s个页面)',
			langCat,
			mw.language.new('zh'):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