https://de.wikipedia.org/w/index.php?action=history&feed=atom&title=Modul%3ATemplUtl%2F01
Modul:TemplUtl/01 - Versionsgeschichte
2025-06-23T03:55:52Z
Versionsgeschichte dieser Seite in Wikipedia
MediaWiki 1.45.0-wmf.6
https://de.wikipedia.org/w/index.php?title=Modul:TemplUtl/01&diff=198308168&oldid=prev
PerfektesChaos: 2019-12-03
2020-03-31T11:43:43Z
<p>2019-12-03</p>
<p><b>Neue Seite</b></p><div>local TemplUtl = { suite = "TemplUtl",<br />
serial = "2019-12-03",<br />
sub = "01",<br />
commons = "i18n/01",<br />
main = 52364930 }<br />
--[=[<br />
Auxilary table generation,<br />
showing strings for boolean values in all known languages.<br />
]=]<br />
local Failsafe = TemplUtl<br />
<br />
<br />
<br />
local fetch = function ()<br />
-- Retrieve specifications from commons:Data:****.tab<br />
-- Postcondition:<br />
-- Returns<br />
-- 1. table, sequence, with data<br />
-- 2. table, with maximum colspan, as number<br />
local storage = string.format( "%s.tab", TemplUtl.commons )<br />
local lucky, data = pcall( mw.ext.data.get, storage, "_" )<br />
local r1 = { }<br />
local r2 = { [false] = 0,<br />
[true] = 0 }<br />
if type( data ) == "table" and<br />
type( data.data ) == "table" then<br />
local o = { }<br />
local t = { }<br />
local e, l, s, w<br />
data = data.data<br />
for i = 1, #data do<br />
e = data[ i ]<br />
if type( e ) == "table" and<br />
type( e[ 1 ] ) == "boolean" and<br />
type( e[ 2 ] ) == "table" then<br />
l = e[ 1 ]<br />
e = e[ 2 ]<br />
for k, v in pairs( e ) do<br />
if type( k ) == "string" and<br />
type( v ) == "string" then<br />
w = mw.text.split( v, "|" )<br />
if #w > r2[ l ] then<br />
r2[ l ] = #w<br />
end<br />
table.insert( o, k )<br />
if not t[ k ] then<br />
t[ k ] = { }<br />
end<br />
t[ k ][ l ] = w<br />
end<br />
end -- for k, v<br />
else<br />
break -- for i<br />
end<br />
end -- for i<br />
table.sort( o )<br />
for i = 1, #o do<br />
s = o[ i ]<br />
e = t[ s ]<br />
if e then<br />
w = { s = s }<br />
if type( e[ false ] ) == "table" then<br />
w[ false ] = e[ false ]<br />
end<br />
if type( e[ true ] ) == "table" then<br />
w[ true ] = e[ true ]<br />
end<br />
table.insert( r1, w )<br />
t[ s ] = false<br />
end<br />
end -- for i<br />
end<br />
return r1, r2<br />
end -- fetch()<br />
<br />
<br />
<br />
local fiat = function ( apply, align, at, around )<br />
-- Create table row<br />
-- Precondition:<br />
-- apply -- table, with data<br />
-- align -- table, with maximum colspan<br />
-- at -- string, with project language code<br />
-- around -- string, with wrapping scripting direction<br />
-- Postcondition:<br />
-- Returns mw.html.TR object<br />
local r = mw.html.create( "tr" )<br />
local e = mw.html.create( "code" )<br />
:attr( "lang", "zxx" )<br />
:wikitext( apply.s )<br />
local scripting<br />
local fk = function ( a, attr )<br />
local td = mw.html.create( "td" )<br />
:attr( "lang", a )<br />
if attr and attr ~= around then<br />
td:attr( "dir", attr )<br />
end<br />
td:wikitext( mw.language.fetchLanguageName( apply.s,<br />
a ) )<br />
return td<br />
end -- fk()<br />
local fv = function ( a )<br />
local v = apply[ a ]<br />
r:newline()<br />
if v then<br />
local k = align[ a ] - #v<br />
for i = 1, #v do<br />
e = mw.html.create( "td" )<br />
:attr( "lang", apply.s )<br />
:wikitext( v[ i ] )<br />
if scripting ~= around then<br />
e:attr( "dir", scripting )<br />
end<br />
r:node( e )<br />
end -- for i<br />
if k > 0 then<br />
e = mw.html.create( "td" )<br />
if k > 1 then<br />
e:attr( "colspan", tostring( k ) )<br />
end<br />
r:node( e )<br />
end<br />
else<br />
r:node( mw.html.create( "td" )<br />
:attr( "colspan",<br />
tostring( align[ a ] ) ) )<br />
end<br />
end -- fv()<br />
if mw.language.new( apply.s ):isRTL() then<br />
scripting = "rtl"<br />
else<br />
scripting = "ltr"<br />
end<br />
if around == "rtl" then<br />
e:attr( "dir", "ltr" )<br />
end<br />
r:newline()<br />
:node( mw.html.create( "td" )<br />
:node( e ) )<br />
:newline()<br />
:node( fk( "en", "ltr" ) )<br />
:newline()<br />
:node( fk( apply.s, scripting ) )<br />
if at ~= "en" then<br />
r:newline()<br />
:node( fk( at ) )<br />
end<br />
fv( false )<br />
fv( true )<br />
return r<br />
end -- fiat()<br />
<br />
<br />
<br />
TemplUtl.f = function ( alien )<br />
-- Create table<br />
-- Precondition:<br />
-- alien -- string, with language code, or not<br />
-- Postcondition:<br />
-- Returns string with entire HTML table<br />
local tbl = mw.html.create( "table" )<br />
:addClass( "wikitable sortable" )<br />
:addClass( "TemplUtl-table-01" )<br />
local tr = mw.html.create( "tr" )<br />
local rows, cols = fetch()<br />
local scripting, slang, speak<br />
if type( alien ) == "string" and<br />
mw.language.isSupportedLanguage( alien ) then<br />
slang = mw.text.trim( alien )<br />
else<br />
local sub = mw.title.getCurrentTitle().subpageText<br />
if sub:find( "%l%l%l?%-?%a?%a?%a?%a?$" ) and<br />
mw.language.isSupportedLanguage( sub ) then<br />
slang = sub<br />
end<br />
if not slang then<br />
slang = mw.language.getContentLanguage():getCode()<br />
end<br />
end<br />
slang = slang:lower()<br />
speak = mw.language.fetchLanguageName( slang )<br />
tbl:attr( "lang", slang )<br />
if mw.language.new( slang ):isRTL() then<br />
scripting = "rtl"<br />
else<br />
scripting = "ltr"<br />
end<br />
tbl:attr( "dir", scripting )<br />
tr:newline()<br />
:node( mw.html.create( "th" )<br />
:wikitext( "ISO&nbsp;639 / BCP47" ) )<br />
:newline()<br />
:node( mw.html.create( "th" )<br />
:wikitext( "English" ) )<br />
:newline()<br />
:node( mw.html.create( "th" )<br />
:wikitext( "*" ) )<br />
:newline()<br />
if slang ~="en" then<br />
tr:node( mw.html.create( "th" )<br />
:attr( "lang", slang )<br />
:wikitext( speak ) )<br />
:newline()<br />
end<br />
tr:node( mw.html.create( "th" )<br />
:attr( "colspan", tostring( cols[ false ] ) )<br />
:wikitext( "0" ) )<br />
:newline()<br />
:node( mw.html.create( "th" )<br />
:attr( "colspan", tostring( cols[ true ] ) )<br />
:wikitext( "1" ) )<br />
tbl:newline()<br />
-- :node( mw.html.create( "thead" )<br />
:node( tr )<br />
-- )<br />
for i = 1, #rows do<br />
tbl:newline()<br />
:node( fiat( rows[ i ], cols, slang, scripting ) )<br />
end -- for i<br />
return tostring( tbl:newline() )<br />
end -- TemplUtl.f()<br />
<br />
<br />
<br />
-- Export<br />
local p = { }<br />
<br />
function p.f( frame )<br />
return TemplUtl.f( frame.args.lang )<br />
end -- p.f<br />
<br />
return p</div>
PerfektesChaos