Owl.png Wiki reading hard on the eyes? Try out our Dark Theme! Visit the preferences page while logged in and select Hydra Dark. Owl.png


From Terraria Wiki
Jump to: navigation, search
Lua logo.svg Documentation The documentation below is transcluded from Module:LangInfo/doc. (edit | history)

Provides the functionality of {{langInfo}}.

The main and only function is go; the kind of information returned is determined by the second unnamed parameter. The table wplinks contains, for every language where it is necessary, the localized page title of the respective language's page about that language.

["en"] = "English language"

This is only necessary if that page title is not equal to the language's lname field in the data module.

local data = mw.loadData('Module:LangInfo/data')

-- manually set Wikipedia link to a language's local "<lang> language" article; in case that differs from the language's endonym
local wplinks = {
	["bg"] = "Български език",
	["zh"] = "汉语",
	["da"] = "Dansk (sprog)",
	["fi"] = "Suomen kieli",
	["de"] = "Deutsche Sprache",
	["hu"] = "Magyar nyelv",
	["it"] = "Lingua italiana",
	["lv"] = "Latviešu valoda",
	["lt"] = "Lietuvių kalba",
	["pl"] = "Język polski",
	["pt"] = "Língua portuguesa",
	["ru"] = "Русский язык",
	["sk"] = "Slovenčina",
	["es"] = "Idioma español",
	["th"] = "ภาษาไทย",
	["uk"] = "Українська мова",

-- manually set country codes for countries whose official language's ISO 639-1 code is not equal to the country's ISO 3166-1 code
local countrycodes = {
	["cs"] = "cz",
	["da"] = "dk",
	["el"] = "gr",
	["en"] = "us",
	["hi"] = "in",
	["ja"] = "jp",
	["ko"] = "kr",
	["sv"] = "se",
	["uk"] = "ua",
	["vi"] = "vn",
	["zh"] = "cn",

local trim = mw.text.trim
local args_table

local getArg = function(key)
	local value = args_table[key]
	if not value then
		return nil
	value = trim(value)
	if value == '' then
		return nil
	return value

-- main return object
return {
go = function(frame, args)
	-- init cache
	args_table = args or frame.args

	local _arg1 = getArg(1) or ''
	local _arg2 = getArg(2) or ''
	if _arg2 == 'name' then
		if data[_arg1]['shortname'] ~= '' then
			return data[_arg1]['shortname']
			return data[_arg1]['fullname']
	elseif _arg2 == 'countrycode' then
		if countrycodes[_arg1] ~= nil then
			return countrycodes[_arg1]
			return _arg1
	elseif _arg2 == 'wplink' and wplinks[_arg1] ~= nil then
		return wplinks[_arg1]
	elseif _arg2 == 'lname' or _arg2 == 'wplink' then
		return ( string.gsub(data[_arg1]['lname'], "(.-),.+", "%1") ) --only get first part of a comma-separated list
	elseif data[_arg1][_arg2] ~= '' then
		return data[_arg1][_arg2]
		return ''