Terraria Wiki

  • Discussions are now available on the Terraria Wiki.
  • Miss the old Hydra Skin? Try out our Hydralize gadget! Visit the preferences page while logged in and turn on the gadget.

READ MORE

Terraria Wiki
m (+"en", "hi" to country codes)
m (+"vi" country code)
Line 32: Line 32:
 
["sv"] = "se",
 
["sv"] = "se",
 
["uk"] = "ua",
 
["uk"] = "ua",
  +
["vi"] = "vn",
 
["zh"] = "cn",
 
["zh"] = "cn",
 
}
 
}

Revision as of 21:33, 16 March 2020

Lua logo 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.

Example:
["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
	end
	value = trim(value)
	if value == '' then
		return nil
	end
	return value
end

-----------------------------------------------------------------
-- 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']
		else
			return data[_arg1]['fullname']
		end
	elseif _arg2 == 'countrycode' then
		if countrycodes[_arg1] ~= nil then
			return countrycodes[_arg1]
		else
			return _arg1
		end
	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]
	else
		return ''
	end
end

}