Modul:TemplateData: Unterschied zwischen den Versionen
2018-04-15
wp>PerfektesChaos (2018-04-05) |
wp>PerfektesChaos (2018-04-15) |
||
Zeile 1: | Zeile 1: | ||
local TemplateData = { suite = "TemplateData", | local TemplateData = { suite = "TemplateData", | ||
serial = "2018-04- | serial = "2018-04-15", | ||
item = 46997995 } | item = 46997995 } | ||
--[=[ | --[=[ | ||
Zeile 212: | Zeile 212: | ||
-- Returns string, with localized text | -- Returns string, with localized text | ||
local o = mw.message.new( "templatedata-" .. adapt ) | local o = mw.message.new( "templatedata-" .. adapt ) | ||
if not Data.slang then | |||
local Multilingual = Fetch( "Multilingual" ) | |||
if type( Multilingual.userLangCode ) == "function" then | |||
Data.slang = Multilingual.userLangCode() | |||
end | |||
end | |||
if Data.slang then | if Data.slang then | ||
o:inLanguage( Data.slang ) | o:inLanguage( Data.slang ) | ||
Zeile 344: | Zeile 350: | ||
local function faraway( alternatives ) | local function faraway( alternatives ) | ||
-- Retrieve | -- Retrieve best language version from multilingual text | ||
-- Parameter: | -- Parameter: | ||
-- alternatives -- table, to be evaluated | -- alternatives -- table, to be evaluated | ||
Zeile 353: | Zeile 359: | ||
local variants = { } | local variants = { } | ||
local r1, r2 | local r1, r2 | ||
if | if Data.slang and | ||
Data.slang = | mw.ustring.codepoint( Data.slang, 1, 1 ) > 122 then | ||
Data.slang = false | |||
end | end | ||
for k, v in pairs( alternatives ) do | for k, v in pairs( alternatives ) do | ||
Zeile 360: | Zeile 367: | ||
v = mw.text.trim( v ) | v = mw.text.trim( v ) | ||
if v ~= "" then | if v ~= "" then | ||
k = k:lower() | |||
variants[ k ] = v | variants[ k ] = v | ||
n = n + 1 | n = n + 1 | ||
Zeile 366: | Zeile 374: | ||
end -- for k, v | end -- for k, v | ||
if n > 0 then | if n > 0 then | ||
local choices, Multilingual | |||
if n > 1 then | |||
choices = { } | |||
end | |||
for k, v in pairs( variants ) do | for k, v in pairs( variants ) do | ||
if n == 1 then | |||
r1 = v | |||
elseif Data.slang == k then | |||
variants[ k ] = nil | |||
r1 = v | |||
r2 = variants | |||
else | |||
table.insert( choices, k ) | |||
end | end | ||
end -- for k, v | end -- for k, v | ||
if not r1 then | if not r1 then | ||
Multilingual = Fetch( "Multilingual" ) | |||
if type( Multilingual.userLang ) == "function" then | |||
local sel = Multilingual.userLang( choices, | |||
TemplateData.frame ) | |||
r1 = variants[ sel ] | |||
variants[ sel ] = nil | |||
r2 = variants | |||
local | |||
end | end | ||
end | end | ||
if r2 then | if r2 then | ||
Multilingual = Multilingual or Fetch( "Multilingual" ) | |||
for k, v in pairs( r2 ) do | for k, v in pairs( r2 ) do | ||
if v and not Multilingual.isLang( k ) | if v and not Multilingual.isLang( k, true ) then | ||
Fault( string.format( "Invalid <code>lang=%s</code>", | Fault( string.format( "Invalid <code>lang=%s</code>", | ||
k ) ) | k ) ) | ||
Zeile 525: | Zeile 511: | ||
end -- for k, v | end -- for k, v | ||
for i = 1, n do | for i = 1, n do | ||
for k, v in pairs( Data.heirs ) do | if Data.heirs then | ||
for k, v in pairs( Data.heirs ) do | |||
if v and not Data.heirs[ v ] then | |||
n = n - 1 | |||
t[ k ].inherits = nil | |||
Data.heirs[ k ] = nil | |||
p2 = { } | |||
t2 = { } | |||
if p[ v ] then | |||
for k2, v2 in pairs( p[ v ] ) do | |||
p2[ k2 ] = v2 | p2[ k2 ] = v2 | ||
end -- for k2, v2 | |||
if p[ k ] then | |||
for k2, v2 in pairs( p[ k ] ) do | |||
if type( v2 ) ~= "nil" then | |||
p2[ k2 ] = v2 | |||
end | |||
end -- for k2, v2 | |||
end | end | ||
p[ k ] = p2 | |||
for k2, v2 in pairs( t[ v ] ) do | |||
t2[ k2 ] = v2 | |||
end -- for k2, v2 | |||
for k2, v2 in pairs( t[ k ] ) do | |||
if type( v2 ) ~= "nil" then | |||
t2[ k2 ] = v2 | |||
end | |||
end -- for k2, v2 | |||
t[ k ] = t2 | |||
else | |||
Fault( "No params[] inherits " .. v ) | |||
end | |||
end | end | ||
end -- for k, v | |||
end | |||
end | |||
end -- i = 1, n | end -- i = 1, n | ||
if n > 0 then | if n > 0 then | ||
Zeile 956: | Zeile 948: | ||
tbl:node( fatten( s ) ) | tbl:node( fatten( s ) ) | ||
Data.order[ i ] = false | Data.order[ i ] = false | ||
elseif s:match( "[=|]" ) then | |||
Fault( string.format( "Bad param <code>%s</code>", | |||
s ) ) | |||
else | else | ||
tbl:node( feature( s ) ) | tbl:node( feature( s ) ) | ||
Zeile 1.286: | Zeile 1.281: | ||
support == "*" then | support == "*" then | ||
Permit.builder[ s ] = true | Permit.builder[ s ] = true | ||
elseif s:match( "^[1-9]%d | elseif s:match( "^[1-9]%d?" ) and | ||
Permit.builder.align then | Permit.builder.align then | ||
Permit.builder.align = tonumber( s ) | Permit.builder.align = tonumber( s ) |