local entry
s = false
if type( collection ) == "table" then
Multilingual.site = Multilingual.site or
mw.wikibase.getGlobalSiteId
entry = collection[ Multilingual.site ]
if entry then
s = ":" .. entry.title
elseif collection.enwiki then
s = "w:en:" .. collection.enwiki.title
end
end
r = Multilingual.wikibase( object, "labels", )
if s then
if s == ":" .. r then
r = string.format( "%s", s )
else
r = string.format( "%s", s, r )
end
end
end
return r or ""
end -- Multilingual.sitelink  
Multilingual.tabData = function ( access, at, alt, )
-- Retrieve translated keyword from commons:Data:****.tab
-- Precondition:
-- access -- string, with page identification on Commons
-- at -- string, with keyword
-- alt -- string|nil|false, with fallback text
-- -- , if available
-- Returns
-- 1. string|nil|false, with selected message
-- 2. language code, or "error"
local data = fetchData( access )
local r1, r2
if type( data ) == "table" then
if type( at ) == "string" then
local seek = mw.text.trim( at )
if seek == "" then
r1 = "EMPTY Multilingual.tabData key"
else
local e, poly
for i = 1, #data do
e = data[ i ]
if type( e ) == "table" then
if e[ 1 ] == seek then
if type( e[ 2 ] ) == "table" then
poly = e[ 2 ]
else
r1 = "INVALID Multilingual.tabData bad #"
.. tostring( i )
end
break -- for i
end
else
break -- for i
end
end -- for i
if poly then
data = poly
else
r1 = "UNKNOWN Multilingual.tabData key: " .. seek
end
end
else
r1 = "INVALID Multilingual.tabData key"
end
else
r1 = data
end
if r1 then
r2 = "error"
elseif data then
r1, r2 = Multilingual.i18n( data, alt, )
r2 = r2 or "error"
end
return r1, r2
end -- Multilingual.tabData  
Multilingual.userLang = function ( accept, )
-- Try to support user language by application
-- Precondition:
-- accept -- string or table
-- space separated list of available ISO 639 codes
-- Default: project language, or English
-- -- , if available
-- Postcondition:
-- Returns string with appropriate code
local s = type( accept )
local codes, r, slang
if s == "string" then
codes = mw.text.split( accept:lower, "%s+" )
elseif s == "table" then
codes = { }
for i = 1, #accept do
s = accept[ i ]
if type( s ) == "string" and
s ~= "" then
table.insert( codes, s:lower )
end
end -- for i
end
slang = User.favorize( codes, )
if slang then
if feasible( slang, codes ) then
r = slang
elseif slang:find( "-", 1, true ) then
slang = Multilingual.getBase( slang )
if feasible( slang, codes ) then
r = slang
end
end
if not r then
local others = mw.language.getFallbacksFor( slang )
for i = 1, #others do
slang = others[ i ]
if feasible( slang, codes ) then
r = slang
break -- for i
end
end -- for i
end
end
if not r then
local back = favorites
for i = 1, #back do
slang = back[ i ]
if feasible( slang, codes ) then
r = slang
break -- for i
end
end -- for i
if not r and codes[ 1 ] then
r = codes[ 1 ]
end
end
return r or favorites[ 1 ]
end -- Multilingual.userLang  
Multilingual.userLangCode = function
-- Guess a user language code
-- Postcondition:
-- Returns code of current best guess
return User.self or favorites[ 1 ]
end -- Multilingual.userLangCode  
Multilingual.wikibase = function ( all, about, attempt, )
-- Optimal translation of wikibase component
-- Precondition:
-- all -- string or table, object ID or entity
-- about -- boolean, true "descriptions" or false "labels"
-- attempt -- string or not, code of preferred language
-- -- , if available
-- Postcondition:
-- Returns
-- 1. string, with selected message
-- 2. string, with language code, or not
local s = type( all )
local object, r, r2
if s == "table" then
object = all
elseif s == "string" then
object = mw.wikibase.getEntity( all )
end
if type( object ) == "table" then
if about and about ~= "labels" then
s = "descriptions"
else
s = "labels"
end
object = object[ s ]
if type( object ) == "table" then
if object[ attempt ] then
r = object[ attempt ].value
r2 = attempt
else
local poly
for k, v in pairs( object ) do
poly = poly or { }
poly[ k ] = v.value
end -- for k, v
if poly then
r, r2 = Multilingual.i18n( poly, nil, )
end
end
end
end
return r or "", r2
end -- Multilingual.wikibase  
Failsafe.failsafe = function ( atleast )
-- Retrieve versioning and check for compliance
-- Precondition:
-- atleast -- string, with required version
-- or wikidata|item|~|@ or false
-- Postcondition:
-- Returns string -- with queried version/item, also if problem
-- false -- if appropriate
-- 2020-08-17
local since = atleast
local last = ( since == "~" )
local linked = ( since == "@" )
local link = ( since == "item" )
local r
if last or link or linked or since == "wikidata" then
local item = Failsafe.item
since = false
if type( item ) == "number" and item > 0 then
local suited = string.format( "Q%d", item )
if link then
r = suited
else
local entity = mw.wikibase.getEntity( suited )
if type( entity ) == "table" then
local seek = Failsafe.serialProperty or "P348"
local vsn = entity:formatPropertyValues( seek )
if type( vsn ) == "table" and
type( vsn.value ) == "string" and
vsn.value ~= "" then
if last and vsn.value == Failsafe.serial then
r = false
elseif linked then
if mw.title.getCurrentTitle.prefixedText
== mw.wikibase.getSitelink( suited ) then
r = false
else
r = suited
end
else
r = vsn.value
end
end
end
end
end
end
if type( r ) == "nil" then
if not since or since <= Failsafe.serial then
r = Failsafe.serial
else
r = false
end
end
return r
end -- Failsafe.failsafe  
-- Export
local p = { }  
p.fair = function
-- Format language code
-- 1 -- language code
local s = mw.text.trim( .args[ 1 ] or "" )
return Multilingual.fair( s ) or ""
end -- p.fair  
p.fallback = function
-- Is another language suitable as replacement?
-- 1 -- language version specifier to be supported
-- 2 -- language specifier of a possible replacement
local s1 = mw.text.trim( .args[ 1 ] or "" )
local s2 = mw.text.trim( .args[ 2 ] or "" )
local r = Multilingual.fallback( s1, s2 )
if type( r ) == "table" then
r = r[ 1 ]
else
r = r and "1" or ""
end
return r
end -- p.fallback  
p.findCode = function
-- Retrieve language code from language name
-- 1 -- name in current project language
local s = mw.text.trim( .args[ 1 ] or "" )
return Multilingual.findCode( s ) or ""
end -- p.findCode  
p.fix = function
local r = .args[ 1 ]
if r then
r = Multilingual.fix( mw.text.trim( r ) )
end
return r or ""
end -- p.fix  
p.format = function
-- Format one or more languages
-- 1 -- language list or item
-- slang -- language of the answer, if not native
-- * -- native
-- ! -- current project
-- any valid code
-- shift -- capitalize, if "c"; downcase, if "d"
-- capitalize first item only, if "f"
-- link -- 1 -- link items
-- scream -- category title in case of error
-- split -- split pattern, if list expected
-- separator -- list separator, else split
-- start -- prepend first element, if any
local r
local link
if .args.link == "1" then
link = true
end
r = Multilingual.format( .args[ 1 ],
.args.slang,
.args.shift,
link,
.args.scream,
,
.args.split,
.args.separator,
.args.start )
return r or ""
end -- p.format  
p.getBase = function
-- Retrieve base language from possibly combined ISO language code
-- 1 -- code
local s = mw.text.trim( .args[ 1 ] or "" )
return Multilingual.getBase( s ) or ""
end -- p.getBase  
p.getName = function
-- Retrieve language name from ISO language code
-- 1 -- code
-- 2 -- language to be used for the answer, if not native
-- ! -- current project
-- * -- native
-- any valid code
local s = mw.text.trim( .args[ 1 ] or "" )
local slang = .args[ 2 ]
local r
Multilingual. =
if slang then
slang = mw.text.trim( slang )
end
r = Multilingual.getName( s, slang )
return r or ""
end -- p.getName  
p.int = function
-- Translated system message
-- 1 -- message ID
-- lang -- language code
-- $1, $2, ... -- parameters
local sysMsg = .args[ 1 ]
local r
if sysMsg then
sysMsg = mw.text.trim( sysMsg )
if sysMsg ~= "" then
local n = 0
local slang = .args.lang
local i, params, s
if slang == "" then
slang = false
end
for k, v in pairs( .args ) do
if type( k ) == "string" then