Pergi ke kandungan

Modul:IPA/category documentation

Daripada Wikipedia, ensiklopedia bebas.
require('strict')

local p = {}
local lects = mw.loadData('Modul:IPA/data/export')
local mLang = require('Modul: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(19)
	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
	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
		'bahasa ' .. name
	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), 'halaman')
		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 'Halaman dengan ' .. parentName .. ' AFA' or
			'Halaman dengan AFA'
	)
	local sortkey = args.sort or
		name:find('^[ %l]+$') and ' ' .. name or
		name
	local ret = {
		string.format(
			'Halaman berikut mengandungi transkripsi [[Abjad Fonetik Antarabangsa|AFA]] [[%s|%s]] menggunakan %s. Jangan menambahkan kategori ini secara manual.',
			link,
			name,
			code
				and string.format('<code>{{[[Templat:AFA|AFA]]|%s|...}}</code>', code)
				or '[[Templat:AFA]]'
		)
	}
	if key then
		table.insert(ret, string.format(
			'Transkripsi akan terpaut kepada kekunci [[%s]] secara lalai. Transkripsi yang tidak mematuhi konvensyen kekunci mesti mempunyai <code>|generic=yes</code>.',
			key
		))
	end
	if isCollective then
		table.insert(ret, string.format(
			'%s ialah sebuah kolektif bahasa. Sila gantikan kod%s dengan bahasa yang lebih khusus jika boleh.',
			name,
			code and ' (' .. code .. ')' or ''
		))
	end
	if not code and args.container ~= 'yes' then
		table.insert(ret, string.format(
			'<small>Ralat pendokumenan: kod bahasa untuk "%s" tidak ditemui.</small>',
			name
		))
	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