This module is invoked by {{language info}} with the invocation {{#invoke:language_info|interwiki_links|en={{#var:_en| {{#titleparts:{{FULLPAGENAME}}}} }}|lang={{lang}} }}
.
Parameters:
- en
- page name, in English
- lang
- language code, see {{langList}} for available codes
{{language info|}} will set these defaults:
- en= either
{{{en|{{{key|}}}}}}
,{{#titleparts:{{FULLPAGENAME}}}} }}
, or{{#titleparts:{{FULLPAGENAME}}|-1}}
,depending on {{langList|isEn|en}} and/or {{langList|isOnWiki|en}}. - lang={{lang}} will determine the language by the pagename/subpagename, defaults to en (English).
The module itself has no defaults, so parameters
and en
must be provided if the module is invoked elsewhere.
lang
The module will iterate through the langList, checking for instances of the page name in the other languages, and string them together in the pattern '[[' .. otherlang .. ':'.. pagename in other language .. ']]'
Note: Make sure an interwiki prefix exists for all language translations (see Special:Interwiki).
It uses
to set the cache variable mw.ext.LuaCache
in :_language_info:data
. This will prevent all the pages calling {{Language info}} from regenerating their cache every time the template (or the data it is using) is edited. When a large number of pages are regenerated in a short span of time, the wiki platform may crash, causing users to get 5xx errors.
Module:Language_info/data
Module:Language info subpages:
Template {{Language info}} subpages:
-- We only invoke this module once per page, therefore we do not need to use mw.loadData()
-- This cache is set in Module:Language_info/data
-- Note:
-- If a template that's being used by large number of page changed, it will causing all of these page's cache to be invalidated and requires regeneration.
-- This may crash wiki platform and cause visitor get 5xx error. So we use luacache to decouple data template and template which uses it.
-- By doing this, editing on data template won't cause massive pages to be regenerated.
local cache = require 'mw.ext.LuaCache'
local info = cache.get(':_language_info:data')
if not info then
require('Module:Language_info/data').purge()
info = cache.get(':_language_info:data') or {}
end
-- temporary fix
local langsOnWiki = {
["bg"] = true,
["cs"] = true,
["da"] = true,
["el"] = true,
["en"] = true,
["fi"] = true,
["id"] = true,
["it"] = true,
["ja"] = true,
["lt"] = true,
["lv"] = true,
["nl"] = true,
["no"] = true,
["ro"] = true,
["sk"] = true,
["sv"] = true,
["th"] = true,
["tr"] = true,
["vi"] = true,
["yue"] = true,
}
return {
interwiki_links = function(frame)
local key = frame.args['en']
local lang = frame.args['lang']
local str = ''
-- local str = '<div style="display:none">languageinfo: en: '..key..' lang: '..lang..'</div>' -- debug code
for k,v in pairs(info) do
if k ~= lang and not(langsOnWiki[k]) then -- skip language on wiki
if v[key] then
str = str .. '[[' .. k .. ':'.. v[key] .. ']]'
end
end
end
return str
end,
}