Ajuda:Only-lua multilanguage infoboxes

De la Viquipèdia, l'enciclopèdia lliure
Multilanguage infoboxes only-lua

The multilanguage templates that use the lua-only mode consist of 4 pages: 1 template that calls one of the 3 modules, and one of these 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 a parameter and a label are assigned at the same time.
cl Same as al, but it will display the label as header, and the text in collapsed mode.
a- Same as a, but the infobox will display it (the text will take up the full width of the infobox).

Creating non-standard parameters and labels in i18n[modifica]

The standard parameters and labels are those provided with the infobox package. Occasionally, you may want:

  • To add new parameters-labels.
  • To change the order of the parameters-labels.
  • To delete parameters-labels.
  • That several parameters, which are not in the standard package, pass their contents to a standard parameter.

Defining keys for non-standard parameters and labels[modifica]

By default:

 local k = {
    -- explanations ...
}

If you want to use two variables, a name must be chosen for the key (taking into account the its features).

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 parameters[modifica]

It must be assigned to the table p.new_items, which by default is:

 p.new_args = {
    [MLMT.k.Args] = {
        -- explanations ...
    },	
    [MLMT.k.Labels] = {
        -- explanations ...
    },
}

For parameter ("Args")[modifica]

Each item consists of:

[key] = {"manual_parameter_name/s", "call to WD"},

When:

  • "manual_parameter_name/s" can be "name" or {"name_1", "name2"}
  • "call to WD" may be:
    • simple, e.g. "_P123456789" or
    • complex, e.g. {property="P123456789", formatting='[http:/web/$1 $1]", ...}
More than one call to WD is supported.

The first or second subitem can be omitted. Omitting a subitem means leaving it between "".

For label[modifica]

Each item consists of:

[key] = "label",

"label" must be:

  • a text or
  • a call to WD, e.g. "_P123456789"

Example[modifica]

To set two parameters (argument and label characteristics), with local_1 and local_2 as their keys:

p.new_items = {
    [MLMT.k.Args] = {
        [k.local_1] = {"local_1", ""},
        [k.local_2] = {"local_2", ""},
    },	
    [MLMT.k.Labels] = {
        [k.local_1] = "Local 1",
        [k.local_2] = "Local 2",
    },
}

If you wanted the second new parameter to be able to be called with two different names, then:

p.new_items = {
    [MLMT.k.Args] = {
        [k.local_1] = {"local_1", ""},
        [k.local_2] = {{"local_2","number"}, ""},
    ...
}

If you want the first parameter to take the value of WD if it has not been entered manually, taking the property Editorial (P123) as an example:

p.new_items = {
    [MLMT.k.Args] = {
        [k.local_1] = {"local_1", "_P123"},
    ...
}

If local_2 were to be a positive integer, the key and the parameter type must be added to p.arg_lims:

p.arg_lims = {
    -- explanations ...
    {k.local_2, "i+"},
}

Parameter appearance order[modifica]

It is for:

  • Modifying the order in which they are displayed in the infobox.
  • Adding non-standard parameter to the required place.

To do this you need to:

  1. Open "Main/items" and copy the table p.idx completely.
  2. Copy its contents to "Main/i18n" which is the module to be modified.
  3. You will need to change the name of the variables in this table named "p.k.." to "Abrev.k...", Abrev as defined at the beginning of this module and following the example would be IPi.
  4. Finally:
  • Modify the order of the items in this table as appropriate and/or
  • Place the new item or items where required. It is necessary to follow the structure established for the other elements.

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 table vals. 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)}, where k.param_1 and k.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.

Modification/construction of an infobox[modifica]

This is when the whole infobox will be programmed in lua.

Besides:

  • The need to number the label and data is omitted as it does so automatically.
  • The presence or not of the headings of a group of elements is facilitated.

To add a new element you need to follow the steps similar to the #Modification/construction of a pre-infobox, although the function names change, so load_arg_of_key and label_of_key are replaced by a single load_show_key, a function sent to infobox the label and the value corresponding to the key, if it finds a value for the key.

To make a simple call to a WD property you need to write it as it is indicated by the use of the infobox.

More easily, it admits

  • Complex calls to WD, for example you can write:
local items = {
    [MLMT.k.Args] = {
        ...
        [Prei.k.new_item] = {"new_item", {"P12345678 OR P87654321",
                                          formatting='[http://www.aweb.org/?id=$1 $1]',
                                          list='firstrank',},
                                          },
        ...
  • Supports multiple calls to WD, in the example if the first call fails, the module does the second call:
local items = {
    [MLMT.k.Args] = {
        ...
        [Prei.k.new_item] = {"new_item", {"P12345678 OR P87654321",
                                          formatting='[http://www.aweb.org/?id=$1 $1]',},
                                         {"P123456789",
                                          formatting='[http://www.otherweb.org/?id=$1 $1',},  
                                          },
        ...
  • Supports formatting for a parameter that is entered only manually, thus:
local items = {
    [MLMT.k.Args] = {
        ...
        [Prei.k.new_item] = {"new_item", {formatting='[http://www.aweb.org/?id=$1 $1]'}},
        ...
  • Supports creating a parameter whose value is only obtained from WD, thus:
local items = {
    [MLMT.k.Args] = {
        ...
        [Prei.k.new_item] = {"", "P12345678",},
        ...

but in this case the function should be modified to ensure that there is no request for the unnamed parameter:

    function arg_names_types_from_key (key)
	return SA.CheckIsStrOrTab (itemsM[MLMT.k.Args][key][1], key), MLMT.IT.s
    end

for a function similar to:

    function arg_names_types_from_key (key)
        if key == Prei.k.new_item then
            return nil
        else
	    return SA.CheckIsStrOrTab (itemsM[MLMT.k.Args][key][1], key), MLMT.IT.s
        end
    end