「モジュール:Wd」の版間の差分

ナビゲーションに移動 検索に移動
en:Module:Wd 2017年10月11日 (水) 06:56(UTC)より
template>K-iczn
(K-iczn (会話) による ID:65892747 の版を取り消し)
template>K-iczn
(en:Module:Wd 2017年10月11日 (水) 06:56(UTC)より)
208行目: 208行目:
end
end


function applyStringParams(str, ...)
function errorText(code, param)  
for i, v in ipairs(arg) do
local error = i18n["errors"][code]
str = mw.ustring.gsub(str, "$"..i, v)
if param then error = mw.ustring.gsub(error, "$1", param) end
end
return error
return str
end
 
function unknownDataTypeError(dataType)
return applyStringParams(i18n['errors']['unknown-data-type'], dataType)
end
end
 
function throwError(errorMessage, param)
function missingRequiredParameterError()
error(errorText(errorMessage, param))
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


585行目: 566行目:
-- 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())
throwError("missing-required-parameter")
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))
throwError("extra-required-parameter", parameters.separator)
end
end
866行目: 847行目:
-- add delimiters for readability
-- add delimiters for readability
value = addDelimiters(value)
value = i18n.addDelimiters(value)
end
end
921行目: 902行目:
end
end
suffix = getOrdinalSuffix(yRound) .. suffix
suffix = i18n.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,219行目: 1,200行目:
itemID = "P" .. itemID
itemID = "P" .. itemID
else
else
return '<strong class="error">' .. unknownDataTypeError(snak.datatype) .. '</strong>'
return '<strong class="error">' .. errorText('unknown-data-type', snak.datatype) .. '</strong>'
end
end
1,230行目: 1,211行目:
return label
return label
else
else
return '<strong class="error">' .. unknownDataTypeError(snak.datavalue.type) .. '</strong>'
return '<strong class="error">' .. errorText('unknown-data-type', snak.datavalue.type) .. '</strong>'
end
end
elseif snak.snaktype == 'somevalue' and not noSpecial then
elseif snak.snaktype == 'somevalue' and not noSpecial then
2,531行目: 2,512行目:
if not frame.args[1] then
if not frame.args[1] then
error(i18n["errors"]["no-function-specified"])
throwError("no-function-specified")
end
end
2,537行目: 2,518行目:
if f == "main" then
if f == "main" then
error(i18n["errors"]["main-called-twice"])
throwError("main-called-twice")
end
end
assert(p["_"..f], applyStringParams(i18n['errors']['no-such-function'], f))
assert(p["_"..f], errorText('no-such-function', f))
-- copy arguments from immutable to mutable table
-- copy arguments from immutable to mutable table
匿名利用者

案内メニュー