Ajuda:Multilanguage module tools/en
This module facilitates the creation of modules for multilingual templates (or their location) that:
- It facilitates the location (i18n) of both the names of past arguments and the tags or messages used, so it creates lists (see below).
- It is occasionally used to make calls to Wikidata in order to complete its elements if they are not entered manually, as is the case with Module:Global infobox tools used to create multilingual infoboxes.
- Generation of lists to facilitate the verification of the names of the parameters, thus warning the user of the existence of an unknown parameter.
- Code generation for TemplateData.
- You can define the type of parameters entered (string -the usual-, integer, number -real-, boolean) that will be used for checking the parameters entered and generating the code for TemplateData.
- It allows modular design, with arguments, labels or messages placed in other modules.
Description
modificaWarning: In the functions described below, a parameter ending with * means that it is optional.
Checking function parameters
modificap.ChkFunc (func_name, params)
It is used in debugging a function, and so a more accurate error message can be given than it could give lua. It can be useful for performing public function checks that can be used by module creators based on this module. Also used in Module:Global infobox tools.
Where:
func_name
is the name of the function to checkparams
is a parameter table, where each element is{name, value, type}
, and:- The
type
can be any of the following in the next table:
- The
a without a specific type b boolean f function i integer k key (a string with value) n number s string with value or not t table x string with value
- adding "r", then the parameter is required
Example:
function p.CheckIdx_arglab (ModuleName, idx, omit_params, for_lua)
MLMT.ChkFunc ("CheckIdx_arglab", { -- The name of the function
{"ModuleName",ModuleName,"xr"}, -- "xr": a required string
{"idx",idx,"tr"}, -- "tr": a required table
{"omit_params",omit_params,"t"}, -- "t": an optional table
{"for_lua",for_lua,"b"}, -- "b": an optional boolean
}
)
Then a call with CheckIdx_arglab ("MyModule", "table")
would give the message:
Lua error: In a call to "CheckIdx_arglab" parameter #2 (= "idx") must be a table, but found "table".
Preset parameters
modificaUsually only for multilingual infoboxes.
p.arg = {
demo = 'demo',
item = 'item',
lang = 'lang',
}
|
function p.DemoItemLang()
Variables and language functions
modificap.lang = nil
It is defined when a value is set for |lang=
, used in the case of demonstrations. In this case the following functions make sense:
function p.LangsDifWriteDirect() = false
If the language is different from the current one, the default value returned is false.function p.WriteDirect()
The writing direction of the language, the default value returned is ltr.
p.compare_lang = 'en'
. It will display in English (en, by default) the lists of labels that use calls to Wikidata (that defines its content in the form of property or qualifier).
function p.IsRTL (frame)
Function that determines whether the writing direction of a language is from right to left the previous one from a frame and with a language defined with |lang=
.
function p.IniLang (args)
Initialize the above values.
Structuring the translation
modificaParameters, labels and messages are structured in two tables:
- One in the main module (Module:AnyName), where you can define (if it is necessary) Wikidata properties or qualifiers, otherwise the translation in (usually) English.
- The other in the i18n module (Module:AnyName/i18n), with the translation in the own language, otherwise will take the value of the table of the main module.
The keys (identifiers of each element, or -keys-) are defined in the items module (Module:AnyName/items).
Both tables should be structured with the following table names:
p.l = {
Args = 'Args',
Labels = 'Labels',
Msgs = 'Msgs',
Errors = 'Errors',
}
|
Labels to define translatable strings parameters text to display usually warning or information messages error messages |
Let's look at an example of the parameters:
Five parameter tags are defined in Module:MLMT age 1/items.
p.k = {
birth_year = 'birth_year',
death_year = 'death_year',
---
years = 'years',
---
birth_after_today = 'birth_after_today',
death_after_birth = 'death_after_today',
}
In the following two modules, they must be headed with:
local MLMT = require "Module:Multilang module tools"
local MLMT_A1i = require "Module:MLMT age 1/items"
The main module (Module: MLMT age 1) defines the arguments and their denominations. Important: a parameter can have several denominations, then these are defined in a table.
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',
},
}
Translations will be assigned to the translation module (Module:MLMT age 1/i18n). These translations will be added to the English denominations of the previous module. In this example the translations are in Catalan.
local items = {
[MLMT.k.Args] = {
[MLMT_A1i.k.birth_year] = "any_naix",
[MLMT_A1i.k.death_year] = "any_mort",
},
[MLMT.k.Labels] = {
[MLMT_A1i.k.years] = "anys",
},
[MLMT.k.Errors] = {
[MLMT_A1i.k.birth_after_today] = "Any de naixement després de l'any en curs",
[MLMT_A1i.k.death_after_birth] = "Any de la mort després de l'any de naixement",
},
}
Shared modules
modificaThey are the modules that supply arguments, labels, or messages to various modules. An example is the Module:Medical infobox items, which supplies some parameters to different infobox modules.
tableMerge
modificaTo add them, use the function: function p.tableMerge (ModuleName, tab_main, tab_lang)
. In this case it should be added in the main module:
itemsM = MLMT.tableMerge (ModuleName, items, IIi18n.items)
Where:
itemsM
, is the table resulting from the merge.IIi18n = require "Module:Infobox images/i18n"
tableMerge
- Check that all translations have a correspondence in the English original. This warns if there is an item in the i18n module that is not in the main module.
- If there is no parameter in the i18n module or it is empty (""), the original value is taken.
- In the case of labels or messages, of course, they will not be added but will be replaced.
Checking parameters
modificafunction p.CheckParamsM (args, ArgsPoss, OtherArgs*)
Where ArgsPoss is a table with the parameter tables. If shared modules are not used, ArgsPoss will be a table with only one element: the table with the module parameters.
Where OtherArgs is a table with acceptable parameters that do not implement the functionality of the module, and that usually serve to obtain lists of arguments with |allitems=
. In the latter case OtherArgs = {"allitems"}.
Labels
modificafunction p.GetLabelL (tab, key, lang)
function p.GetLabel (tab, key)
Lists
modifica{{#invoke:Module name|main function|allitems=Possibility}}
Where Possibility must be:
- params: Possible arguments or parameters.
- template: Presents the code of the TemplateData, to be copied to the documentation of the template calling the module.
- labels: Table with the name of the labels called Wikidata, with their correspondence in English and the translation into the language of Wikipedia. With
|lang=
, it offers the alternative translation to the one of the Wikipedia: the choice. Allows you to link and complete translations. - msgs: Information messages that complement the result. Content is not assignable to a Wikidata property or qualifier.
- errors: Error messages, for which the course of the program will usually be stopped and the error text will be displayed. Content is not assignable to a Wikidata property or qualifier.
Keep it up:
p.LOpt = {
params = 'params',
template = 'template',
labels = 'labels',
msgs = 'msgs',
errors = 'errors',
}
|
Display list options, id p.l |
p.IT = {
s = 's',
i = 'i',
ipos = 'i+',
n = 'n',
npos = 'n+',
d = 'd',
b = 'b',
sz = 'sz',
a = 'a',
}
|
parameter type string integer positive integer number positive number date boolean size array |
p.uses_QP_for_labels = false
--if true appears in labels list a column with Qualifiers or Properties of Wikidata
Lets you get lists of argument, labels, or message that appear in a module
function p.all_items_opt (args, opt)
function p.add_mod_used (abbrev, name)
The main functions of the lists are similar and use the optional tab_modname_func
parameter when there are shared modules. This parameter is a table of tables where each subtable refers to one of the shared modules. So if "Module:Shared1" is shared, then tab_modname_func = {{"Shared1", function_referred_to_Shared1}}
.
Parameter lists and TemplateData code
modificafunction p.show_arg_items (option, idx, func, tab_modname_func*)
- Where option is "param" or "template".
- Where idx is the list of parameters (located in /items).
- Where func is a function (local, to be created) that returns: the abbreviation of the module, the master table, the translated table (in /i18n), the parameter type, if required.
- The module abbreviation will be used as the first column if there are shared modules, where each module will have an abbreviation. If there are shared modules the abbreviation with the link-name in the modules used will appear at the end of the generated list of parameters, otherwise only the name/link.
- The variable type is a
p.IT
value (look at here), is optional, and the default value is "s". Used in TemplateData. To determine what can be used:function p.GetArgType (key, tab_int, tab_num, tab_date, tab_bool)
function p.GetArgTypeGrp (grp, key, tab_int, tab_num, tab_date, tab_bool)
, for grouped parameters
- Required is optional, and the default is false. Used in TemplateData. To determine if can be used:
function p.GetRequired (key, tab)
function p.GetRequiredGrp (grp, key, tab)
, for grouped parameters
Functions for shared modules of parameters:
function p.add_arg_item (option, mod_abbrev, key, wd_main, wd_lang, lims)
function p.add_arg_item_grp (option, mod_abbrev, grp, key, wd_main, wd_lang, lims)
Lists of labels
modificafunction p.show_lab_items (idx, func, tab_modname_func*)
- Where idx is the list of labels (located in /items).
- Where func is a function (local, to be created) that returns: the abbreviation of the module, the master table, the translated table (in /i18n). Uses
GetLabelX
.- The module abbreviation will be used as the first column if there are shared modules, where each module will have an abbreviation. If there are shared modules the abbreviation with the link-name in the modules used will appear at the end of the generated list of parameters, otherwise only the name/link.
function p.GetLabelX (mod_abbrev, key, tab_main, tab_lang)
Functions for shared modules of labels:
function p.add_lab_item (mod_abbrev, key, wd_main, wd_lang, lnk)
function p.add_lab_item_grp (mod_abbrev, grp, key, wd_main, wd_lang, lnk)
Lists of normal and error messages
modificafunction p.show_msgs_errors (idx, func, tab_modname_func*)
- Where idx is the list of normal or error messages (located in /items).
- Where func is a function (local, to be created) that returns: the abbreviation of the module, the master table, the translated table (in /i18n). Uses
GetMsgErrorX
.- The module abbreviation will be used as the first column if there are shared modules, where each module will have an abbreviation. If there are shared modules the abbreviation with the link-name in the modules used will appear at the end of the generated list of parameters, otherwise only the name/link.
function p.GetMsgErrorX (option, mod_abbrev, key, tab_main, tab_lang)
Functions for shared modules of messages:
function p.add_msg_error_item (mod_abbrev, key, wd_main, wd_lang)
function p.add_msg_error_item_grp (mod_abbrev, grp, key, wd_main, wd_lang)