Modul:TemplateData: Unterschied zwischen den Versionen
2019-05-28
w>PerfektesChaos (2019-05-18) |
w>PerfektesChaos (2019-05-28) |
||
Zeile 1: | Zeile 1: | ||
local TemplateData = { suite = "TemplateData", | local TemplateData = { suite = "TemplateData", | ||
serial = "2019-05- | serial = "2019-05-28", | ||
item = 46997995 } | item = 46997995 } | ||
--[=[ | --[=[ | ||
Zeile 183: | Zeile 183: | ||
-- Returns slang, or not | -- Returns slang, or not | ||
if type( Data.slang ) == "nil" then | if type( Data.slang ) == "nil" then | ||
local Multilingual = Fetch( "Multilingual" ) | local Multilingual = Fetch( "Multilingual", true ) | ||
if type( Multilingual.userLangCode ) == "function" then | if Multilingual and | ||
type( Multilingual.userLangCode ) == "function" then | |||
Data.slang = Multilingual.userLangCode() | Data.slang = Multilingual.userLangCode() | ||
else | else | ||
Data.slang = | Data.slang = mw.language.getContentLanguage():getCode() | ||
:lower() | |||
end | end | ||
end | end | ||
Zeile 376: | Zeile 378: | ||
local variants = { } | local variants = { } | ||
local r1, r2 | local r1, r2 | ||
for k, v in pairs( alternatives ) do | for k, v in pairs( alternatives ) do | ||
if type( v ) == "string" then | if type( v ) == "string" then | ||
Zeile 388: | Zeile 389: | ||
end -- for k, v | end -- for k, v | ||
if n > 0 then | if n > 0 then | ||
local | local Multilingual = Fetch( "Multilingual", true ) | ||
if Multilingual and | |||
type( Multilingual.i18n ) == "function" then | |||
local sel = Multilingual.i18n( variants ) | |||
if sel then | |||
if | |||
r1 = variants[ sel ] | r1 = variants[ sel ] | ||
variants[ sel ] = nil | variants[ sel ] = nil | ||
Zeile 413: | Zeile 399: | ||
end | end | ||
end | end | ||
if | if not r1 then | ||
Foreign() | |||
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 | |||
end | |||
end -- for k, v | |||
end | |||
if r2 and Multilingual then | |||
for k, v in pairs( r2 ) do | for k, v in pairs( r2 ) do | ||
if v and not Multilingual.isLang( k, true ) then | if v and not Multilingual.isLang( k, true ) then | ||
Fault( string.format( " | Fault( string.format( "%s <code>lang=%s</code>", | ||
"Invalid", | |||
k ) ) | k ) ) | ||
end | end | ||
Zeile 1.747: | Zeile 1.745: | ||
free() | free() | ||
if JSONutil then | if JSONutil then | ||
Data.got = JSONutil.fetch( Data.source, | local Multilingual = Fetch( "Multilingual", true ) | ||
local f | |||
if Multilingual then | |||
f = Multilingual.i18n | |||
end | |||
Data.got = JSONutil.fetch( Data.source, true, f ) | |||
else | else | ||
local lucky | local lucky |