K-iczn (会話) による ID:65892747 の版を取り消し
template>K-iczn (en:Module:Wd 2017年10月11日 (水) 00:24(UTC)より) |
template>K-iczn |
||
208行目: | 208行目: | ||
end | end | ||
function | function applyStringParams(str, ...) | ||
for i, v in ipairs(arg) do | |||
str = mw.ustring.gsub(str, "$"..i, v) | |||
return | end | ||
return str | |||
end | |||
function unknownDataTypeError(dataType) | |||
return applyStringParams(i18n['errors']['unknown-data-type'], dataType) | |||
end | end | ||
function | |||
function missingRequiredParameterError() | |||
return i18n['errors']['missing-required-parameter'] | |||
end | |||
function extraRequiredParameterError(param) | |||
return applyStringParams(i18n['errors']['extra-required-parameter'], param) | |||
end | |||
function getOrdinalSuffix(num) | |||
return i18n.getOrdinalSuffix(num) | |||
end | |||
function addDelimiters(num) | |||
return i18n.addDelimiters(num) | |||
end | end | ||
566行目: | 585行目: | ||
-- make sure that at least one required parameter has been defined | -- make sure that at least one required parameter has been defined | ||
if not next(root.req) then | if not next(root.req) then | ||
error(missingRequiredParameterError()) | |||
end | end | ||
-- make sure that the separator parameter "%s" is not amongst the required parameters | -- make sure that the separator parameter "%s" is not amongst the required parameters | ||
if root.req[parameters.separator] then | if root.req[parameters.separator] then | ||
error(extraRequiredParameterError(parameters.separator)) | |||
end | end | ||
847行目: | 866行目: | ||
-- add delimiters for readability | -- add delimiters for readability | ||
value = | value = addDelimiters(value) | ||
end | end | ||
902行目: | 921行目: | ||
end | end | ||
suffix = | suffix = getOrdinalSuffix(yRound) .. suffix | ||
else | else | ||
-- if not verbose, take the first year of the century/millennium | -- if not verbose, take the first year of the century/millennium | ||
1,200行目: | 1,219行目: | ||
itemID = "P" .. itemID | itemID = "P" .. itemID | ||
else | else | ||
return '<strong class="error">' .. | return '<strong class="error">' .. unknownDataTypeError(snak.datatype) .. '</strong>' | ||
end | end | ||
1,211行目: | 1,230行目: | ||
return label | return label | ||
else | else | ||
return '<strong class="error">' .. | return '<strong class="error">' .. unknownDataTypeError(snak.datavalue.type) .. '</strong>' | ||
end | end | ||
elseif snak.snaktype == 'somevalue' and not noSpecial then | elseif snak.snaktype == 'somevalue' and not noSpecial then | ||
2,512行目: | 2,531行目: | ||
if not frame.args[1] then | if not frame.args[1] then | ||
error(i18n["errors"]["no-function-specified"]) | |||
end | end | ||
2,518行目: | 2,537行目: | ||
if f == "main" then | if f == "main" then | ||
error(i18n["errors"]["main-called-twice"]) | |||
end | end | ||
assert(p["_"..f], | assert(p["_"..f], applyStringParams(i18n['errors']['no-such-function'], f)) | ||
-- copy arguments from immutable to mutable table | -- copy arguments from immutable to mutable table |