Module:Language

local p = {} local Data = mw.loadData("Module:Language/Data")

local Region = require("Module:Region")

local CATEGORY_INVALID_ARGS = "" local DEFAULT_FLAG_SIZE = "20px"

-- The enum is ordered according to Guidelines:Translations -- enAm, enBr, ja, then ordered by language name function p.enum(options) local options = options or {} local includeWikiLanguage = options.includeWikiLanguage or false local enum = {} for code in pairs(Data.lects) do		if code ~= "enAm" and code ~= "enBr" and code ~= "ja" then local lect = p.getLect(code) table.insert(enum, {				code = code,				name = lect.name,				abbr = lect.abbr,				lang = lect.lang,			}) end end

table.sort(enum, function(a, b)		return a.lang < b.lang	end)

for i, v in ipairs(enum) do		enum[i] = v.code end table.insert(enum, 1, "ja") table.insert(enum, 1, "enBr")

if includeWikiLanguage then table.insert(enum, 1, "enAm") end enum.reference = "Module:Language/Data" return enum end

function p.getLect(code, options) local options = options or {} local flagSize = options.flagSize or DEFAULT_FLAG_SIZE local lect = Data.lects[code] if not lect then local utilsError = require("Module:UtilsError") utilsError.warn(string.format("Invalid language code . See Module:Language/Data for a list of supported languages.", code)) return nil, CATEGORY_INVALID_ARGS end

if lect.variant then name = lect.variant.name.." "..lect.lang local exp = mw.getCurrentFrame:expandTemplate({			title = "Exp",			args = {lect.variant.name, lect.variant.abbr}		}) abbr = lect.lang..""..exp.."" else name = lect.lang abbr = lect.lang end local region = Region.getRegion(lect.flag, { flagSize = flagSize })

return { abbr = abbr, flags = region.flags, lang = lect.lang, name = name, } end

function p.Data(frame) local utilsLayout = require("Module:UtilsLayout") local utilsMarkup = require("Module:UtilsMarkup") local headers = {"Code", "Flag(s)", "Language", "", "Abbr."} local sortable = {1, 3, 4, 5} local rows = {} for i, code in ipairs(p.enum) do		local lect = p.getLect(code) local flags = #lect.flags > 1 and utilsMarkup.list(lect.flags) or lect.flags[1] table.insert(rows, {" ", flags, lect.lang, lect.name, lect.abbr}) end local wikitable = utilsLayout.table({		headers = headers,		sortable = sortable,		rows = rows,	}) return wikitable end

function p.Documentation(frame) return { enum = { params = {"options"}, returns = "A list of language codes for use by Module:UtilsArg and Module:Documentation.", cases = { outputOnly = true, {					args = {}, },				{					args = { { includeWikiLanguage = true }, },				},			},		},		getLect = { params = {"code", "options"}, returns = { "A Lua table of information on a particular (a language or variant thereof), or   if the given code does not exist in Module:Language/Data.", "An error category if the given code does not exist in Module:Language/Data.", },			cases = { outputOnly = true, {					args = {"enBr"}, expect = { -- {						-- 	abbr = 'EnglishBR', -- 	lang = "English", -- 	name = "British English", -- 	flags = { -- 		' ',						-- 	},													-- },					},				},				{					args = {"ja", { flagSize = "40px" }}, expect = { {							abbr = "Japanese", lang = "Japanese", name = "Japanese", flags = { ' ',							},						}					}				},				{					args = {"zhT"}, expect = { -- {						-- 	abbr = "Chinese'\"`UNIQ--templatestyles-00000009-QINU`\"'TR", -- 	lang = "Chinese", -- 	name = "Traditional Chinese", -- 	flags = { -- 		' ',						-- 		'  ',						-- 		'  ',						-- 	},						-- }					}				},				{					args = {"narnia"}, expect = { nil, CATEGORY_INVALID_ARGS }				},			}		}	} end

function p.Schemas(frame) return { Data = { type = "record", required = true, properties = { {					name = "lects", required = true, type = "map", desc = "A list of (languages or variants thereof) relevant to .", keyPlaceholder = "code", keys = { type = "string", desc = "A identifying code for the lect. This should be an code. For variants, append a one- or two-character abbreviation.", },					values = { type = "record", properties = { {								name = "lang", required = true, type = "string", desc = "The name of the language.", },							{								name = "flag", required = true, type = "string", desc = "A region code identifying a flag (or flags) to associate to the language.", },							{								name = "variant", type = "record", properties = { {										name = "abbr", type = "string", required = true, desc = "An abbreviation of the language variant name.", },									{										name = "name", type = "string", required = true, desc = "A representing the language variant." },								},							},						},					},				},			},		},		enum = { options = { type = "record", properties = { {						name = "includeWikiLanguage", default = false, desc = "If true, the wiki's native language is included in the list.", },				},			},		},		getLect = { code = { required = true, type = "string", desc = "A code from Module:Language/Data.", },			options = { type = "record", properties = { {						name = "flagSize", type = "string", default = DEFAULT_FLAG_SIZE, desc = "An for the returned flag(s).", },				},			},		},	} end

return p