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 (+country codes)
m (Undo revision 1109360 by Boilpoil (talk) Apparently does not work)
Tag: Undo
(9 intermediate revisions by 3 users not shown)
Line 26: Line 26:
 
["da"] = "dk",
 
["da"] = "dk",
 
["el"] = "gr",
 
["el"] = "gr",
  +
["en"] = "us",
  +
["hi"] = "in",
 
["ja"] = "jp",
 
["ja"] = "jp",
 
["ko"] = "kr",
 
["ko"] = "kr",
 
["sv"] = "se",
 
["sv"] = "se",
 
["uk"] = "ua",
 
["uk"] = "ua",
  +
["vi"] = "vn",
  +
["yue"] = "cn",
 
["zh"] = "cn",
 
["zh"] = "cn",
 
}
 
}
Line 59: Line 63:
 
local _arg2 = getArg(2) or ''
 
local _arg2 = getArg(2) or ''
 
 
 
if not data[_arg1] then
 
return
 
end
 
if _arg2 == 'name' then
 
if _arg2 == 'name' then
 
if data[_arg1]['shortname'] ~= '' then
 
if data[_arg1]['shortname'] ~= '' then
Line 64: Line 71:
 
else
 
else
 
return data[_arg1]['fullname']
 
return data[_arg1]['fullname']
  +
end
 
elseif _arg2 == 'countrycode' then
 
if countrycodes[_arg1] ~= nil then
  +
return countrycodes[_arg1]
 
else
  +
return _arg1
 
end
 
end
 
elseif _arg2 == 'wplink' and wplinks[_arg1] ~= nil then
 
elseif _arg2 == 'wplink' and wplinks[_arg1] ~= nil then
Line 71: Line 84:
 
elseif data[_arg1][_arg2] ~= '' then
 
elseif data[_arg1][_arg2] ~= '' then
 
return data[_arg1][_arg2]
 
return data[_arg1][_arg2]
elseif _arg2 == 'countrycode' then
 
if countrycodes[_arg1] ~= nil then
 
return countrycodes[_arg1]
 
else
 
return _arg2
 
end
 
 
else
 
else
 
return ''
 
return ''

Revision as of 16:41, 2 March 2021

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",
	["yue"] = "cn",
	["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 not data[_arg1] then
		return
	end
	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

}