end
return r
end -- find  
local fold = function
-- Merge template and #invoke arglist
-- Precondition:
-- -- template
-- Postcondition:
-- table, with combined arglist
local r = { }
local f = function ( apply )
if type( apply ) == "table" and
type( apply.args ) == "table" then
for k, v in pairs( apply.args ) do
v = mw.text.trim( v )
if v ~= "" then
r[ tostring( k ) ] = v
end
end -- for k, v
end
end -- f
f( :getParent )
f
return r
end -- fold  
User.favorize = function ( accept, )
-- Guess user language
-- Precondition:
-- accept -- sequence table, with offered ISO 639 etc. codes
-- -- , if available
-- Postcondition:
-- Returns string with best code, or nil
if not ( User.self or User.langs ) then
if not User.trials then
User.tell = mw.message.new( User.sniffer )
if User.tell:exists then
User.trials = { }
if not Multilingual. then
if then
Multilingual. =
else
Multilingual. = mw.getCurrentFrame
end
end
User.sin = Multilingual.:callParserFunction( "int",
User.sniffer )
else
User.langs = true
end
end
if User.sin then
local order = { }
local post = { }
local three = { }
local unfold = { }
local s, sin
for i = 1, #accept do
s = accept[ i ]
if not User.trials[ s ] then
if #s > 2 then
if s:find( "-", 3, true ) then
table.insert( unfold, s )
else
table.insert( three, s )
end
else
if Multilingual.prefer[ s ] then
table.insert( order, s )
else
table.insert( post, s )
end
end
end
end -- for i
for i = 1, #post do
table.insert( order, post[ i ] )
end -- for i
for i = 1, #three do
table.insert( order, three[ i ] )
end -- for i
for i = 1, #unfold do
table.insert( order, unfold[ i ] )
end -- for i
for i = 1, #order do
s = order[ i ]
sin = User.tell:inLanguage( s ):plain
if sin == User.sin then
User.self = s
break -- for i
else
User.trials[ s ] = true
end
end -- for i
end
end
return User.self
end -- User.favorize  
Multilingual.fair = function ( ask )
-- Format language specification according to RFC 5646 etc.
-- Precondition:
-- ask -- string or table, as created by .getLang
-- Postcondition:
-- Returns string, or false
local s = type( ask )
local q, r
if s == "table" then
q = ask
elseif s == "string" then
q = Multilingual.getLang( ask )
end
if q and
q.legal and
mw.language.isKnownLanguageTag( q.base ) then
r = q.base
if q.n > 1 then
local order = { "extlang",
"script",
"region",
"other",
"extension" }
for i = 1, #order do
s = q[ order[ i ] ]
if s then
r = string.format( "%s-%s", r, s )
end
end -- for i
end
end
return r or false
end -- Multilingual.fair  
Multilingual.fallback = function ( able, another )
-- Is another language suitable as replacement?
-- Precondition:
-- able -- language version specifier to be supported
-- another -- language specifier of a possible replacement,
-- or not to retrieve a fallback table
-- Postcondition:
-- Returns boolean, or table with fallback codes
local r
if type( able ) == "string" and #able > 0 then
if type( another ) == "string" and #another > 0 then
if able == another then
r = true
else
local s = Multilingual.getBase( able )
if s == another then
r = true
else
local others = mw.language.getFallbacksFor( s )
r = feasible( another, others )
end
end
else
local s = Multilingual.getBase( able )
if s then
r = mw.language.getFallbacksFor( s )
if r[ 1 ] == "en" then
local d = fetchISO639( "fallback" )
if type( d ) == "table" and
type( d[ s ] ) == "string" then
r = mw.text.split( d[ s ], "|" )
table.insert( r, "en" )
end
end
end
end
end
return r or false
end -- Multilingual.fallback  
Multilingual.findCode = function ( ask )
-- Retrieve code of local (current project or English) language name
-- Precondition:
-- ask -- string, with presumable language name
-- A code itself will be identified, too.
-- Postcondition:
-- Returns string, or false
local seek = mw.text.trim( ask )
local r = false
if #seek > 1 then
if seek:find( "[", 1, true ) then
local wlink = fetch( "WLink" )
if wlink and
type( wlink.getPlain ) == "function" then
seek = wlink.getPlain( seek )
end
end
seek = mw.ustring.lower( seek )
if Multilingual.isLang( seek ) then
r = Multilingual.fair( seek )
else
local collection = favorites
for i = 1, #collection do
r = find( seek, collection[ i ] )
if r then
break -- for i
end
end -- for i
end
end
return r
end -- Multilingual.findCode  
Multilingual.fix = function ( attempt )
-- Fix frequently mistaken language code
-- Precondition:
-- attempt -- string, with presumable language code
-- Postcondition:
-- Returns string with correction, or false if no problem known
local r = fetchISO639( "correction" )[ attempt:lower ]
return r or false
end -- Multilingual.fix  
Multilingual.format = function ( apply, alien, alter, active, alert,
, assembly, adjacent, ahead )
-- Format one or more languages
-- Precondition:
-- apply -- string with language list or item
-- alien -- language of the answer
-- -- nil, false, "*": native
-- -- "!": current project
-- -- "#": code, downcased, space separated
-- -- "-": code, mixcase, space separated
-- -- any valid code
-- alter -- capitalize, if "c"; downcase all, if "d"
-- capitalize first item only, if "f"
-- downcase every first word only, if "m"
-- active -- link items, if true
-- alert -- string with category title in case of error
-- -- if available
-- assembly -- string with split pattern, if list expected
-- adjacent -- string with list separator, else assembly
-- ahead -- string to prepend first element, if any
-- Postcondition:
-- Returns string, or false if apply empty
local r = false
if apply then
local slang
if assembly then
local bucket = mw.text.split( apply, assembly )
local shift = alter
local separator
if adjacent then
separator = adjacent
elseif alien == "#" or alien == "-" then
separator = " "
else
separator = assembly
end
for k, v in pairs( bucket ) do
slang = Multilingual.format( v, alien, shift, active,
alert )
if slang then
if r then
r = string.format( "%s%s%s",
r, separator, slang )
else
r = slang
if shift == "f" then
shift = "d"
end
end
end
end -- for k, v
if r and ahead then
r = ahead .. r
end
else
local single = mw.text.trim( apply )
if single == "" then
r = false
else
local lapsus, slot
slang = Multilingual.findCode( single )
if slang then
if alien == "-" then
r = slang
elseif alien == "#" then
r = slang:lower
else
r = Multilingual.getName( slang, alien )
if active then
slot = fill( slang, false, )
if slot then
local wlink = fetch( "WLink" )
if wlink and
type( wlink.getTarget )
== "function" then
slot = wlink.getTarget( slot )
end
else
lapsus = alert
end
end
end
else
r = single
if active then
local title = mw.title.makeTitle( 0, single )
if title.exists then
slot = single
end
end
lapsus = alert
end
if not r then
r = single
elseif alter == "c" or alter == "f" then
r = mw.ustring.upper( mw.ustring.sub( r, 1, 1 ) )
.. mw.ustring.sub( r, 2 )
elseif alter == "d" then
if Multilingual.isMinusculable( slang, r ) then
r = mw.ustring.lower( r )
end
elseif alter == "m" then
if Multilingual.isMinusculable( slang, r ) then
r = mw.ustring.lower( mw.ustring.sub( r, 1, 1 ) )
.. mw.ustring.sub( r, 2 )
end
end
if slot then
if r == slot then
r = string.format( "%s", r )
else
r = string.format( "%s", slot, r )
end
end
if lapsus and alert then
r = string.format( "%s", r, alert )
end
end
end
end
return r
end -- Multilingual.format  
Multilingual.getBase = function ( ask )
-- Retrieve base language from possibly combined ISO language code
-- Precondition:
-- ask -- language code
-- Postcondition:
-- Returns string, or false
local r
if ask then
local slang = ask:match( "^%s*(%a%a%a?)-?%a*%s*$" )
if slang then
r = slang:lower
else
r = false
end
else
r = false
end
return r
end -- Multilingual.getBase  
Multilingual.getLang = function ( ask )
-- Retrieve components of a RFC 5646 language code
-- Precondition:
-- ask -- language code with subtags
-- Postcondition:
-- Returns table with formatted subtags
-- .base
-- .region
-- .script
-- .suggest
-- .year
-- .extension
-- .other
-- .n
local tags = mw.text.split( ask, "-" )
local s = tags[ 1 ]
local r
if s:match( "^%a%a%a?$" ) then