Module:Language

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search

The source of truth for languages relevant to The Legend of Zelda series.

This module exports the following functions.

enum

enum([options])

Parameters

Returns

Examples

#InputOutput
1
enum()
{
  "enBr",
  "ja",
  "zhT",
  "zhS",
  "cs",
  "da",
  "nl",
  "fi",
  "frF",
  "frC",
  "de",
  "el",
  "hu",
  "it",
  "ko",
  "he",
  "no",
  "pl",
  "ptB",
  "ptP",
  "ru",
  "esL",
  "esS",
  "sv",
  reference = "[[Module:Language/Data]]",
}
2
enum({ includeWikiLanguage = true })
{
  "enAm",
  "enBr",
  "ja",
  "zhT",
  "zhS",
  "cs",
  "da",
  "nl",
  "fi",
  "frF",
  "frC",
  "de",
  "el",
  "hu",
  "it",
  "ko",
  "he",
  "no",
  "pl",
  "ptB",
  "ptP",
  "ru",
  "esL",
  "esS",
  "sv",
  reference = "[[Module:Language/Data]]",
}

getLect

getLect(code, [options])

Parameters

Returns

  • A Lua table of information on a particular lect (a language or variant thereof), or nil if the given code does not exist in Module:Language/Data.

Examples

#InputOutputStatus
3
getLect("enBr")
{
  abbr = "English<sup>'\"`UNIQ--templatestyles-0000004D-QINU`\"'<span class=\"zw-exp\">'\"`UNIQ--templatestyles-0000004E-QINU`\"'<span class=\"zw-tooltip\">BR<span class=\"zw-tooltip__text noexcerpt\">British</span></span></span></sup>",
  lang = "English",
  variant = "British",
  name = "British English",
  flags = {
    '<span class="tooltip" title="The United Kingdom of Great Britain and Northern Ireland">[[File:United Kingdom Flag.png|20px|The United Kingdom of Great Britain and Northern Ireland]]</span>',
  },
}
4
getLect("ja", { flagSize = "40px" })
{
  abbr = "Japanese",
  lang = "Japanese",
  name = "Japanese",
  flags = {
    '<span class="tooltip" title="Japan">[[File:Japan Flag.png|40px|Japan]]</span>',
  },
}
5
getLect("zhT")
{
  abbr = "Chinese<sup>'\"`UNIQ--templatestyles-0000000D-QINU`\"'<span class=\"zw-exp\">'\"`UNIQ--templatestyles-0000000E-QINU`\"'<span class=\"zw-tooltip\">TR<span class=\"zw-tooltip__text noexcerpt\">Traditional</span></span></span></sup>",
  lang = "Chinese",
  variant = "Traditional",
  name = "Traditional Chinese",
  flags = {
    '<span class="tooltip" title="The Republic of China">[[File:Taiwan Flag.svg|20px|The Republic of China]]</span>',
    '<span class="tooltip" title="The Hong Kong Special Administrative Region of China">[[File:Hong Kong Flag.svg|20px|The Hong Kong Special Administrative Region of China]]</span>',
    '<span class="tooltip" title="The Macao Special Administrative Region of China">[[File:Macao Flag.svg|20px|The Macao Special Administrative Region of China]]</span>',
  },
}
6
getLect("hylian")
nil

local p = {}

local Region = require("Module:Region")
local Data = mw.loadData("Module:Language/Data")
local DEFAULT_FLAG_SIZE = "20px"

function p.Main(frame)
	local code = frame:getParent().args[1] or ""
	local lect = p.getLect(code)
	if not lect then
		local Error = require("Module:Error")
		local cat = require("Module:Constants/category/invalidArgs")
		local errMsg = string.format("Invalid language code <code>%s</code>", code)
		return Error.error(errMsg).."[[Category:"..cat.."]]"
	end
	return lect.name
end

-- The enum is ordered according to [[Guidelines:Translations#Order_of_Languages]]
-- 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
		return nil
	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.."<sup>"..exp.."</sup>"
	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,
		variant = lect.variant and lect.variant.name
	}
end

return p