Module:ISO 3166

Hello, you have come here looking for the meaning of the word Module:ISO 3166. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:ISO 3166, but we will also tell you about its etymology, its characteristics and you will know how to say Module:ISO 3166 in singular and plural. Everything you need to know about the word Module:ISO 3166 you have here. The definition of the word Module:ISO 3166 will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:ISO 3166, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module implements the template {{ISO 3166}}.


local concat = table.concat
local html_create = mw.html.create
local insert = table.insert
local require = require
local upper = string.upper

local format_categories = require("Module:utilities").format_categories
local full_link = require("Module:links").full_link
local language_link = require("Module:links").language_link
local plain_link = require("Module:links").plain_link
local process_params = require("Module:parameters").process
local show_labels = require("Module:labels").show_labels

local en = require("Module:languages").getByCode("en")
local mul = require("Module:languages").getByCode("mul")

local export = {}

local function insert_link(main_text, text, wiki)
	if #main_text == 0 then
		text = text:gsub("^.", upper)
	end
	insert(main_text, plain_link{
		lang = mul,
		term = wiki,
		alt = text
	})
end

function export.show(frame)
	local boolean = {type = "boolean"}
	local required_num = {required = true, type = "number"}
	local params = {
		 = required_num,
		 = {required = true},
		 = true,
		 = boolean,
		 = true,
		 = boolean,
		 = boolean,
		 = true
	}
	
	local parent_args = frame:getParent().args
	if parent_args == "1" then
		insert(params, 2, required_num)
	end
	
	local args = process_params(parent_args, params)
	
	local labels = {"international standards"}
	if args.obs then
		insert(labels, "obsolete")
	end
	local label = show_labels{
		lang = mul,
		labels = labels
	}
	
	local main_text, categories = {}, {}
	
	if args.obs then
		insert(main_text, "Former")
	end
	if args.exr then
		insert_link(main_text, "exceptionally reserved", "w:ISO 3166-1 alpha-2#Exceptional reservations")
	end
	if args.inr then
		insert_link(main_text, "indeterminately reserved", "w:ISO 3166-1 alpha-2#Indeterminate reservations")
	end
	
	if args == 1 then
		insert_link(main_text, "ISO 3166-1", "w:ISO 3166-1")
		if args == 2 or args == 3 then
			insert_link(main_text, "alpha-" .. args, "w:ISO 3166-1 alpha-" .. args)
		else
			error("The parameter \"2\" must be 2 or 3.")
		end
		insert(main_text, language_link{
			lang = en,
			term = "country code",
		})
		insert(main_text, "for")
		insert(main_text, full_link(
			{
				lang = en,
				term = args,
				alt = args or args
			},
			"term"
		))
		insert(categories, "ISO 3166-1 alpha-" .. args)
	elseif args == 2 or args == 3 then
		insert_link(main_text, "ISO 3166-" .. args, "w:ISO 3166-" .. args)
		insert(main_text, language_link{
			lang = en,
			term = "country code",
		})
		insert(main_text, "for")
		insert(main_text, full_link(
			{
				lang = en,
				term = args,
				alt = args or args
			},
			"term"
		))
	    insert(categories, "ISO 3166-" .. args)
	else
		error("The parameter \"1\" must be 1, 2 or 3.")
	end
	
	if args.from then
		if args.to then
			insert(main_text, "from " .. args.from .. " to " .. args.to)
		else
			insert(main_text, "since " .. args.from)
		end
	elseif args.to then
		insert(main_text, "until " .. args.to)
	end
	
	categories = format_categories(categories, mul)
	
	return label .. " " .. tostring(html_create("span")
		:addClass("use-with-mention")
		:wikitext(concat(main_text, " ") .. ".")) .. categories
end

return export