Ajuda:Multilanguage preinfoboxes
The multilanguage infoboxes that use preinfoboxes, consist of 6 pages: 1 template that calls for one of the 3 modules and 2 templates. The last template calls the infobox module.
Label-parameter types
[modifica]Type | Function |
---|---|
a |
for the argument (or parameter) |
l o L |
for the l abel, without capitalizing or putting the first character of the label text). |
al |
if it is assigned a parameter and a label at the same time. |
Creating non-standard parameters in i18n
[modifica]The standard parameters are those provided with the infobox package. Occasionally you may want
- To change the format of a parameter
- To have several parameters (usually non-standard) give their content to one of the standard parameters.
This involves three steps at the end of the module main/i18n:
- Defining keys for non-standard parameters. Keys defined in
local k
. - Definition of non-standard variables. Variables defined in
p.new_args
. - Establish how variables that give a value to a standard variable are managed. Via
function p.local_func
.
Defining keys for non-standard parameters
[modifica]By default:
local k = { -- explanations ... }
If you want to use two variables, a name must be chosen for the key (with letters from "a" to "z", "_" and numbers that are not as the first character).
For example for local_1
and local_2
:
local k = { -- explanations ... local_1 = "local_1", local_2 = "local_2", }
Note that the key name and its value as a string are the same. This has nothing to do with the name under which the article editor will use it, and which is explained below.
This repetition is a lua language requirement and ensures proper subsequent use.
Defining non-standard parameter names
[modifica]By default:
p.new_args = { -- explanations ... }
Then (and for example) to set two parameters you need to define their name. Suppose they are local_1
and local_2
. Then, using parameter types, it will be used as follows:
p.new_args = { -- explanations [k.local_1] = "local_1", [k.local_2] = "local_2", }
If local_2 were to be a positive integer, and an other name added to it, it could be changed to:
p.new_args = { -- explanations [k.local_1] = {"local_1","Local 1"}, [k.local_2] = "local_2", }
Defining constraints for non-standard parameters
[modifica]Optionally you can set constraints, with the syntax already explained here. For example, for a positive integer:
p.new_lims = { -- explanations [k.local_1] = "i+", }
Set how variables are handled
[modifica]At the end of the i18n is the function:
function p.local_func (frame, args) vals = {} - explanations ... return vals end
That returns none (default option) or multiple assignments to parameters.
The parameters of the function passed to it are::
frame
: sometimes required for a function (expandTemplate
, see below).args
: is a function that returns the value of a parameter or an empty string.
vals
: is a table that will not contain any item to several items. Where each element contains the name of the standard target parameter and instructions that send it a value.
Each result will be associated with a parameter where you want the result to be displayed:
- So if
result_for_this_param
contains the value of an element, thanks to some operations that are explained in the following subsection. - With
table.insert (vals, {target_param_name, result_for_this_param})
the item will be written to the tablevals
. It is necessary to define to which standard parameter (target_param_name
) you want to send the result of the operation that was carried out with the (usually) non-standard parameters.
Operations with variables
[modifica]The following is preceded by a line result_for_this_param=
, in order to store the value in this variable.
Know how to program minimally with lua:
- for example. for two lines:
args(k.param_1)..'</br>'..args(k.param_2)
Or a module call:
require ("Module: Module_name_to_call").called_function (parameter_list)
Where:
parameter_list
is the list of comma-separated parameters in{}
:
- for example:
{separator= <br>', args(k.param_1), args(k.param_2)}
With a template, if you don't know how to program in lua or a template is a better solution:
frame: expandTemplate { -- ← the initial curly bracket title = "template_name", args = {the_args} } -- ← the last curly bracket
Where:
template_name
is the name of the template to use; must be written between""
.the_args
are the parameters to send to the template to use
- for example:
{args(k.param_1), args(k.param_2)}
, wherek.param_1
andk.param_2
are the keys of the two non-standard parameters. - You can also read: callParserFunction and expandTemplate for more details and examples of how to write the parameters to pass.
Set the position of non-standard parameters
[modifica]New parameters created will be positioned in the lists generated by the infoboxes (of arguments and labels, or only of arguments) and in the code by the TemplateData.
Alternatively you can decide where you want to put them, so there is the table p.new_pos
. This table consists of an item list in which each item containts two keys:
- The key of the non-standard parameter.
- The key of the parameter above the non-standard. If there are several non-standard parameters, the above parameter can be a non-standard parameter as long as it has already been positioned in a previous item.
Example:
p.new_pos = { {k.local_1, IPi.k.prior}, {k.local_2, k.local_1}, }
If positioning is used, it must be used for all new settings.
Modification/construction of a pre-infobox
[modifica]Introduction
[modifica]The package have two different parts:
- The pre-infobox or modules in lua, which will send the parameters and labels to:
- The template in wiki language.
This situation is more laborious and the execution of the infobox is slower, but it is not necessary to know how to program in lua.
Add a new item
[modifica]If you want to add a new item, which like most items, it will have a label and take a value.
To exemplify this, we want to add "New Item".
The following steps must be followed carefully:
A "Main/items":
[modifica]- Add an key name for "New Item" and it will be used in all modules. If the name were "new_item".
- Write in the middle of the list (and where appropriate, to facilitate the search, in order of appearance in the infobox, and only for this reason):
p.k = { ... new_item = "new_item", ... }
- Write (and where appropriate) in the list:
p.idx = { ... {"al", p.k.new_item}, ... }
The first element is according to the label-parameter type.
In "Main"
[modifica]Suppose that "Main/items" has been defined as "Pi", it will appear at the beginning of the module as:
local Pi = require "Module:Main/items"
- Write (where appropriate) in the list of parameters:
local items = { [MLMT.k.Args] = { ... [Prei.k.new_item] = {"new_item", "",}, ...
If you want it to take the value of the property P12345678, write:
local items = { [MLMT.k.Args] = { ... [Prei.k.new_item] = {"new_item", "_P12345678",}, ...
Note that the property is preceded by the underscore.
If it depended on two possible values, P12345678 and P87654321, type "_P12345678-P87654321"
- Write (and where appropriate) in the label list:
local items = { [MLMT.k.Labels] = { ... [Prei.k.new_item] = "New item", ...
Thus, by default, the label to be submitted will be "New item". We will change it.
In "Main/i18n"
[modifica]Suppose that "Main/items" has been defined as "Pi", it will appear at the beginning of the module as:
local Pi = require "Module:Main/items"
Add translation:
- Write (and where appropriate) in the of parameter list:
local items = { [MLMT.k.Args] = { ... [Prei.k.new_item] = "nou_element", --Catalan translation ...
This way, the article editor can use Prei.k.new_item
from |nou_element=
or |new_item=
.
If it had not been written in this section or simply written down:
local items = { [MLMT.k.Args] = { ... [Prei.k.new_item] = "", ...
The value would only be called from |new_item=
.
If you want more than one input form in the localized form, for example "nova_entrada", you should write:
local items = { [MLMT.k.Args] = { ... [Prei.k.new_item] = {"nou_element","nova_entrada"}, --Catalan translations ...
- Write (and where appropriate) in the label list:
local items = { .... [MLMT.k.Labels] = { ... [Prei.k.new_item] = "Nou element", --Catalan translation ...
This "Nou element" will replace "New item" set to "Prei".
Parameter checks
[modifica]In order to assign a parameter type to the parameters, the following table must be written in "Main/items" and the name of arg_lims
. If you want the new item to be only a number, type:
p.arg_lims = { ... {p.k.new_item', 'i'}, ... }
The p.arg_lims
table will usually already exist in Main/items, otherwise it is written in the module code:
i18n = GIBT.SetAttribToArgs (i18n, {})
- for listsi18nM = GIBT.SetAttribToArgs (i18nM, {})
- for infobox.
Then it will have to change to:
i18n = GIBT.SetAttribToArgs (i18n, Pi.arg_lims)
- for listsi18nM = GIBT.SetAttribToArgs (i18nM, Pi.arg_lims)
- for infobox.
No other changes should be made unless the capture of the parameter is to have unusual behavior.
Assigning default values to parameters
[modifica]An example could be the entry of an integer, which is not assigned manually by the article editor, to a default value. In these cases, and always in the main module, it must be put before the GIBT.std_lab_arg_to_tab
function (the function that captures the manually assigned parameters).
For example, if you want to set a default width of 160 to the Prei.k.width
key. Then the function should be added:
GIBT.arg_of_key (args, i18nM, Prei.k.width, 160, true)
.
If in this same example the width also has a label then the function should be added:
GIBT.arg_label_of_key (args, i18nM, Prei.k.width, 160)
.
Modifications to the template
[modifica]The template will receive the following module values: {{{val_new_item|}}}
and {{{lbl_new_item|}}}
.
Add a header
[modifica]This is to repeat the steps above as if the header was a label, and logically follow the steps only for the tag ([MLMT.k.Labels]
). It is a good practice to add as a key the prefix hd_
to the key name, the key name will appear in bold in the lists.