Modul:Multilingual: Unterschied zwischen den Versionen
2018-02-19
w>PerfektesChaos (2017-11-26) |
w>PerfektesChaos (2018-02-19) |
||
| Zeile 1: | Zeile 1: | ||
local Multilingual = { suite = "Multilingual", | local Multilingual = { suite = "Multilingual", | ||
serial = " | serial = "2018-02-19", | ||
item = 47541920 } | |||
| Zeile 456: | Zeile 457: | ||
return r | return r | ||
end -- Multilingual.getName() | end -- Multilingual.getName() | ||
Multilingual.int = function ( access, alien, apply ) | |||
-- Translated system message | |||
-- Precondition: | |||
-- access -- message ID | |||
-- alien -- language code | |||
-- apply -- nil, or sequence table with parameters $1, $2, ... | |||
-- Postcondition: | |||
-- Returns string, or false | |||
local o = mw.message.new( access ) | |||
local r | |||
if o:exists() then | |||
if type( alien ) == "string" then | |||
o:inLanguage( alien ) | |||
end | |||
if type( apply ) == "table" then | |||
o:params( apply ) | |||
end | |||
r = o:plain() | |||
end | |||
return r or false | |||
end -- Multilingual.int() | |||
| Zeile 601: | Zeile 626: | ||
Multilingual.failsafe = function ( assert ) | |||
-- Retrieve versioning and check for compliance | -- Retrieve versioning and check for compliance | ||
-- Precondition: | -- Precondition: | ||
-- assert -- string, with required version, or false | -- assert -- string, with required version or "wikidata", | ||
-- or false | |||
-- Postcondition: | -- Postcondition: | ||
-- Returns string with appropriate version, or false | -- Returns string with appropriate version, or false | ||
local since = assert | |||
local r | local r | ||
if | if since == "wikidata" then | ||
local item = Multilingual.item | |||
since = false | |||
r = Multilingual.serial | if type( item ) == "number" and item > 0 then | ||
local entity = mw.wikibase.getEntity( string.format( "Q%d", | |||
item ) ) | |||
if type( entity ) == "table" then | |||
local vsn = entity:formatPropertyValues( "P348" ) | |||
if type( vsn ) == "table" and | |||
type( vsn.value) == "string" and | |||
vsn.value ~= "" then | |||
r = vsn.value | |||
end | |||
end | |||
end | |||
end | |||
if not r then | |||
if not since or since <= Multilingual.serial then | |||
r = Multilingual.serial | |||
else | |||
r = false | |||
end | |||
end | end | ||
return r | return r | ||
| Zeile 695: | Zeile 740: | ||
return r or "" | return r or "" | ||
end -- p.getName | end -- p.getName | ||
p.int = function ( frame ) | |||
-- Translated system message | |||
-- 1 -- message ID | |||
-- lang -- language code | |||
-- $1, $2, ... -- parameters | |||
local sysMsg = frame.args[ 1 ] | |||
local r | |||
if sysMsg then | |||
sysMsg = mw.text.trim( sysMsg ) | |||
if sysMsg ~= "" then | |||
local n = 0 | |||
local slang = frame.args.lang | |||
local i, params, s | |||
if slang == "" then | |||
slang = false | |||
end | |||
for k, v in pairs( frame.args ) do | |||
if type( k ) == "string" then | |||
s = k:match( "^%$(%d+)$" ) | |||
if s then | |||
i = tonumber( s ) | |||
if i > n then | |||
n = i | |||
end | |||
end | |||
end | |||
end -- for k, v | |||
if n > 0 then | |||
local s | |||
params = { } | |||
for i = 1, n do | |||
s = frame.args[ "$" .. tostring( i ) ] or "" | |||
table.insert( params, s ) | |||
end -- for i | |||
end | |||
r = Multilingual.int( sysMsg, slang, params ) | |||
end | |||
end | |||
return r or "" | |||
end -- p.int | |||
| Zeile 736: | Zeile 824: | ||
p.failsafe = function ( frame ) | p.failsafe = function ( frame ) | ||
local since = frame.args[ 1 ] | -- Versioning interface | ||
local s = type( frame ) | |||
local since | |||
if s == "table" then | |||
since = frame.args[ 1 ] | |||
elseif s == "string" then | |||
since = frame | |||
end | |||
if since then | if since then | ||
since = mw.text.trim( since ) | since = mw.text.trim( since ) | ||
| Zeile 744: | Zeile 839: | ||
end | end | ||
return Multilingual.failsafe( since ) or "" | return Multilingual.failsafe( since ) or "" | ||
end | end -- p.failsafe() | ||