--[=[
This module is a rewrite of the existing wikitext template {{Language with name/for}}. The primary purpose of
the rewrite is to bring the non-English text into the template so that it can be marked up by {{lang}}.
To accomodate the variety of uses of the template, news parameters are introduced to allow variable styling.
supported parameters (original)
{{{1}}} – language tag
{{{2}}} – non-English 'term' to be wrapped in {{lang}} using tag in {{{1}}}; modified to accept keyword 'none' to prevent categorization
{{{3}}} – English translation of {{{2}}} in single quotes; alias: |term1=
|links= – 'yes' or 'no'; default is 'yes'; links language name derived from {{{2}}}
supported parameters (new)
|term1= – alias of {{{3}}}
|term2= .. |termn= – additional 'or'-like translations; each rendered in single quotes; quoted terms separated by '<space>/<space>'
|italic-term= 'yes' or 'no'; default is 'no'; useful to multi-term translations when all should be italicized
|lang-name= – for those cases where ISO 639 does not have a language tag; {{{1}}} ignored; template wraps {{{2}}} with {{lang}} using 'mis' (uncoded language)
|break= – 'yes' or 'no'; default is 'no'; inserts <br /> between {{{2}}} and the rest of the rendering
|paren= – takes one of three values:
'none' – omit left and right parens around '<language-name> for <term>'
'left' – includes left paren, omits right paren
'right' – includes right paren, omits left paren
because this template now calls {{lang}} properly, it also supports the {{lang}} parameters:
|rtl=
|italic= (and aliases |italics= and |i=)
|size=
|cat=
|nocat=
basic rendering
<non-English text> (<language-name> for '<term>')
multiple terms
<non-English text> (<language-name> for '<term>' / '<term>' / '<term>')
|paren=none
<non-English text> <language-name> for '<term>'
|break=yes
<non-English text><br />(<language-name> for '<term>')
|italic-term=yes
<non-English text> (<language-name> for '<i><term></i>' / '<i><term></i>' / '<i><term></i>')
|lang-name=<lang-name>
<non-English text> ([[<lang-name> language|<lang-name>]] for '
]=]
require ('strict');local get_args = require ('Module:Arguments').getArgs;local lang_mod = require ('Module:Lang');
----------------------------< E R R O R _ M E S S A G E >----------------------------------------------------
render an error message with help-text link and category.
local function error_message (message) local err_msg_t = ; -- open span and initial bit of the error message table.insert (err_msg_t, message); -- the rest of the message table.insert (err_msg_t, ' (help)'); -- the help link
local namespace = mw.title.getCurrentTitle.namespace; -- namespace number if 0
namespace then table.insert (err_msg_t, ''); -- categorize in main and template namespaces end
return table.concat (err_msg_t); -- make a big string and doneend
--termn= parameters. Return a string where each term is insingle quotes. If more than one |termn= parameter, separate each term with
local function terms_get (args_t) local function render_term (term, is_italic) -- local function to do the rendering if is_italic then term = term:gsub ('.+', '%1'); -- apply italic markup; html to avoid converting to when quoted end if is_italic or term:match ('[^\']\'\'$') then term = term:gsub ('.+', ''%1
''); else term = term:gsub ('.+', ''%1''); -- quote using ' in case term uses italic or bold wikimarkup end return term; -- done this was to avoid second string.gsub return value endlocal is_italic = 'yes'
type (k) and k:match ('term%d') then -- string parameter names only table.insert (terms, k:match ('term(%d+)') .. '=' .. v); -- convert k/v pairs to a sequence that can be sorted by |termn= enumerator (enum=term) end end table.sort (terms, function (a, b) -- sort the sequence using local sort function local enum_a = a:match ('^%d+'); -- make numbers for the comparison local enum_b = b:match ('^%d+'); return tonumber(enum_a) < tonumber(enum_b) -- and compare end ); for i, v in ipairs (terms) do -- rewrite the sequence to be sorted sequence of terms terms[i] = render_term (v:gsub ('%d+=(.+)', '%1'), is_italic); -- extract term; italicize as required, and quote end
return table.concat (terms, ' / '); -- form a string and doneend
--lang-name= has avalue, override any value that might be in with 'mis' (uncoded languages)
TODO: error condition when both of and |lang-name= have values?
local function text_make (lang_params_t) if not lang_params_t[2] then return ; end
return lang_mod._lang (lang_params_t);end
--lang-name= overrides . Language name links to languagearticle through '
local function lang_make (args_t, lang_params_t) if args_t['lang-name'] then if 'no'
----------------------------< _ L A N G N F >----------------------------------------------------------------
entry point from another module
local function _langnf (args_t) if not (args_t[1] or args_t['lang-name']) then return error_message ('missing language tag or language name'); end
if (args_t[1] and args_t['lang-name']) then return error_message ('only one of and |lang-name= allowed'); end
if not (args_t[3] or args_t.term1) then return error_message ('missing English translation'); end
local lang_params_t =
local out_t = ; -- components of the rendering go here local left_paren = ('none'
args_t.paren) and or '('; local right_paren = (not args_t[2] or 'none'
args_t.paren or 'none'
table.insert (out_t, text_make (lang_params_t)); -- the non-English text marked up by table.insert (out_t, 'yes'
--langnf}}
local function langnf (frame) local args_t = get_args (frame); return _langnf (args_t)end
----------------------------< E X P O R T S >----------------------------------------------------------------
return