Mòdul:MLMT age 1
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
First example for Module:Multilang module tools. This example is of no real use, it is for educational purposes only.
Link to this module:
- Module:MLMT age 1/items, tag definition and list order (used in this module and the next 118n module).
- Module:MLMT age 1/i18n, localization.
Also you can look Module:MLMT age 2.
Similar to the next example, but without grouping arguments and without introduction message.
Examples
[modifica]main
[modifica]{{#invoke:MLMT age 1|main|1957|2001}}
-> 44 anys
{{#invoke:MLMT age 1|main|1957}}
-> 67 anys
{{#invoke:MLMT age 1|main|any_naix=1957}}
-> Error de Lua: El nom de paràmetre "any_naix" no és vàlid.
{{#invoke:MLMT age 1|main|mort=2013|any_naix=1957}}
-> Error de Lua: El nom de paràmetre "mort" no és vàlid.
{{#invoke:MLMT age 1|main|any_mort=2000}}
-> Error de Lua: "any_naix/birth_year/1" = No té un valor assignat.
main1
[modifica]{{#invoke:MLMT age 1|main1|2001|1957}}
-> Error de Lua: Any de la mort després de l'any de naixement.
{{#invoke:MLMT age 1|main1|2057}}
-> Error de Lua: Any de naixement després de l'any en curs.
main2
[modifica]{{#invoke:MLMT age 1|main2|2001|1957}}
-> Error de Lua: "any_mort/death_year/2" = 1.957 és menor de 2.001.
{{#invoke:MLMT age 1|main2|2057}}
-> Error de Lua: "any_naix/birth_year/1" = 2.057 és major de 2.024.
Lists
[modifica]{{#invoke:MLMT age 1|main|allitems=params}}
Key | Default names | Localized names (i18n) | T. |
---|---|---|---|
birth_year | birth_year, 1 | any_naix | i+-R |
death_year | death_year, 2 | any_mort | i+ |
{{#invoke:MLMT age 1|main|allitems=template}}
<templatedata>
{
"params": {
"any_naix": {
"aliases": [
"birth_year",
["1"]
],
"type": "number",
"required": true
},
"any_mort": {
"aliases": [
"death_year",
["2"]
],
"type": "number"
}
},
"format": "block"
}
</templatedata>
{{#invoke:MLMT age 1|main|allitems=labels}}
Key | Source | Localization (i18n) |
---|---|---|
years | years | anys |
{{#invoke:MLMT age 1|main|allitems=errors}}
Key | Source | Translation |
---|---|---|
birth_after_today | Birth year after current year | Any de naixement després de l'any en curs |
death_after_today | Death year after birth year | Any de la mort després de l'any de naixement |
local p = {}
local SD = require "Module:SimpleDebug"
local SA = require "Module:SimpleArgs"
local MLMT = require "Module:Multilang module tools/prova"
local A1i = require "Module:MLMT age 1/items"
local A1i18n = require "Module:MLMT age 1/i18n"
local ModuleName = 'MLMT age 1'
local items = {
[MLMT.k.Args] = {
[A1i.k.birth_year] = {"birth_year",1},
[A1i.k.death_year] = {"death_year",2},
},
[MLMT.k.Labels] = {
[A1i.k.years] = "years",
},
[MLMT.k.Errors] = {
[A1i.k.birth_after_today] = 'Birth year after current year',
[A1i.k.death_after_birth] = 'Death year after birth year',
},
}
function p.main (frame, mode)
--INITIALIZATION
local ModuleName = 'MLMT age 1'
local args, NArgs = SA.GetArgs (frame)
MLMT.IniLang (frame, args)
local itemsM = MLMT.tableMerge (ModuleName, items, A1i18n.items)
--END INITIALIZATION
function Arg (key)
return itemsM[MLMT.k.Args][key]
end
function Error (key)
return error (itemsM[MLMT.k.Errors][key],0)
end
--BEGIN--
local res = MLMT.ItemList_or_TempData (args, {MLMT.LOpt.params,MLMT.LOpt.template,MLMT.LOpt.labels,MLMT.LOpt.errors},
'A1', ModuleName, items, A1i18n.items,
A1i.idxArgs, A1i.arg_lims,
A1i.idxLabels,
nil, --messages
A1i.idxErrors)
if res == nil then --main
local current_year = tonumber(os.date("%Y", absolutetime))
local birth_year = nil
local end_year = nil
if mode == 1 then
birth_year = SA.RInt_Par (args, Arg(A1i.k.birth_year))
if birth_year > current_year then
return Error (A1i.k.birth_after_today)
end
end_year = SA.Int_Par (args, Arg(A1i.k.death_year))
else
birth_year = SA.RInt_Par (args, Arg(A1i.k.birth_year), nil, current_year)
end_year = SA.Int_Par (args, Arg(A1i.k.death_year), nil, birth_year, current_year)
end
if end_year == nil then
end_year = current_year
elseif birth_year > end_year then
return Error (A1i.k.death_after_birth)
end
MLMT.CheckParams (args, {itemsM})
return end_year-birth_year..' '..itemsM[MLMT.k.Labels][A1i.k.years]
else
return res
end
end --main
function p.main1 (frame)
return p.main (frame, 1)
end
function p.main2 (frame)
return p.main (frame, 2)
end
return p