Mòdul:MLMT age 2
A continuació es mostra la documentació transclosa de la subpàgina /ús. [salta a la caixa de codi]
Second 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 2/items, tag definition and list order (used in this module and the next 118n module).
- Module:MLMT age 2/i18n, localization.
The first example Module:MLMT age 1.
Similar to the prior example, but with grouping arguments and with introduction message.
Examples
[modifica]main1
[modifica]{{#invoke:MLMT age 2|main1|1957|2001}}
-> 44 anys
{{#invoke:MLMT age 2|main1|1957}}
-> 67 anys
{{#invoke:MLMT age 2|main1|birth_year=1957}}
-> Error de Lua: El nom de paràmetre "birth_year" no és vàlid.
{{#invoke:MLMT age 2|main1|any_naix=1957|intro=true}}
-> Error de Lua: El nom de paràmetre "any_naix" no és vàlid.
{{#invoke:MLMT age 2|main1|mort=2013|any_naix=1957}}
-> Error de Lua: El nom de paràmetre "mort" no és vàlid.
{{#invoke:MLMT age 2|main1|any_mort=2000}}
-> Error de Lua: "any_naix/birth_year/1" = No té un valor assignat.
{{#invoke:MLMT age 2|main1|2001|1957}}
-> Error de Lua: Any de la mort després de l'any de naixement.
{{#invoke:MLMT age 2|main1|2057}}
-> Error de Lua: Any de naixement després de l'any en curs.
main2
[modifica]{{#invoke:MLMT age 2|main2|2001|1957}}
-> Error de Lua: "any_mort/death_year/2" = 1.957 és menor de 2.001.
{{#invoke:MLMT age 2|main2|2057}}
-> Error de Lua: "any_naix/birth_year/1" = 2.057 és major de 2.024.
Lists
[modifica]{{#invoke:MLMT age 2|main|allitems=params}}
Key | Default names | Localized names (i18n) | T. |
---|---|---|---|
year.birth | birth_year, 1 | any_naix | i+-R |
year.death | death_year, 2 | any_mort | i+ |
other.intro | intro | b |
{{#invoke:MLMT age 2|main|allitems=template}}
<templatedata>
{
"params": {
"any_naix": {
"aliases": [
"birth_year",
["1"]
],
"type": "number",
"required": true
},
"any_mort": {
"aliases": [
"death_year",
["2"]
],
"type": "number"
},
"intro": {
"type": "boolean"
}
},
"format": "block"
}
</templatedata>
{{#invoke:MLMT age 2|main|allitems=labels}}
Key | Source | Localization (i18n) |
---|---|---|
years | years | anys |
{{#invoke:MLMT age 2|main|allitems=msgs}}
Key | Source | Translation |
---|---|---|
intro | The age is | L'edat és |
{{#invoke:MLMT age 2|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 A2i = require "Module:MLMT age 2/items"
local A2i18n = require "Module:MLMT age 2/i18n"
local ModuleName = 'MLMT age 2'
local items = {
[MLMT.k.Args] = {
[SA.HasChild] = true,
[A2i.k.year] = {
[A2i.k.birth] = {"birth_year",1},
[A2i.k.death] = {"death_year",2},
},
[A2i.k.other] = {
[A2i.k.intro] = "intro",
},
},
[MLMT.k.Labels] = {
[A2i.k.years] = "years",
},
[MLMT.k.Msgs] = {
[A2i.k.intro] = "The age is",
},
[MLMT.k.Errors] = {
[A2i.k.birth_after_today] = 'Birth year after current year',
[A2i.k.death_after_birth] = 'Death year after birth year',
},
}
function p.main (frame, mode)
--INITIALIZATION
local ModuleName = 'MLMT age 2'
local args, NArgs = SA.GetArgs (frame)
MLMT.IniLang (frame, args)
local itemsM = MLMT.tableMerge (ModuleName, items, A2i18n.items)
--END INITIALIZATION
function ArgY (key)
return itemsM[MLMT.k.Args][A2i.k.year][key][1]
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.msgs,MLMT.LOpt.errors},
'A2', ModuleName, items, A2i18n.items,
A2i.idxArgs, A2i.arg_lims,
A2i.idxLabels,
A2i.idxMsgs,
A2i.idxErrors)
if res == nil then --main
itemsM = MLMT.SetAttribToArgs (itemsM, A2i.arg_lims)
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, ArgY(A2i.k.birth))
if birth_year > current_year then
return Error (A2i.k.birth_after_today)
end
end_year = SA.Int_Par (args, ArgY(A2i.k.death))
else
birth_year = SA.RInt_Par (args, ArgY(A2i.k.birth), nil, current_year)
end_year = SA.Int_Par (args, ArgY(A2i.k.death), nil, birth_year, current_year)
end
if end_year == nil then
end_year = current_year
elseif birth_year > end_year then
return Error (A2i.k.death_after_birth)
end
intro = SA.Bool_Par (args, itemsM[MLMT.k.Args][A2i.k.other][A2i.k.intro][1])
MLMT.CheckParams (args, {itemsM[MLMT.k.Args]})
local res = end_year-birth_year..' '..itemsM[MLMT.k.Labels][A2i.k.years]
if intro then
res = itemsM[MLMT.k.Msgs][A2i.k.intro].. ' '..res
end
return res
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