Module:dercat: difference between revisions

From Wiktionary, the free dictionary
Jump to navigation Jump to search
Content deleted Content added
add "languages" after family names
m +|bor=[number]
Tags: Reverted Mobile edit Mobile web edit Advanced mobile edit
Line 6: Line 6:
[2] = { list = true, required = true },
[2] = { list = true, required = true },
inh = { type = "number" },
inh = { type = "number" },
bor = { type = "number" },
}
}
Line 27: Line 28:
if args.inh and i <= args.inh then
if args.inh and i <= args.inh then
add_category("inherited", source_lang_name)
add_category("inherited", source_lang_name)
end
if args.bor and i <= args.bor then
add_category("borrowed", source_lang_name)
end
end
end
end

Revision as of 07:56, 1 October 2021

Used by {{dercat}}.


local export = {}

function export.dercat(frame)
	local parameters = {
		[1] = { required = true },
		[2] = { list = true, required = true },
		inh = { type = "number" },
		bor = { type = "number" },
		
	}
	local args = require "Module:parameters".process(frame:getParent().args, parameters)
	
	local target_lang = require "Module:languages".getByCode(args[1], 1)
	local target_lang_name = target_lang:getCanonicalName()
	local categories = {}
	local function add_category(adjective, source_lang_name)
		table.insert(categories, target_lang_name .. " terms " .. adjective
			.. " from " .. source_lang_name)
	end
	for i, source_lang_code in ipairs(args[2]) do
		-- Accept family and etymology language codes.
		local source_lang = require "Module:languages".getByCode(source_lang_code, i, true, true)
		local source_lang_name = source_lang:getCanonicalName()
		if source_lang:getType() == "family" then
			source_lang_name = source_lang_name .. " languages"
		end
		add_category("derived", source_lang_name)
		if args.inh and i <= args.inh then
			add_category("inherited", source_lang_name)
		end
		if args.bor and i <= args.bor then
			add_category("borrowed", source_lang_name)
		end
	end
	return require "Module:utilities".format_categories(categories, target_lang)
end

return export