Module:Lang: Difference between revisions

Jump to navigation Jump to search
1,937 bytes added ,  10 months ago
no edit summary
m (1 revision imported from wikipedia:Module:Lang)
No edit summary
Line 1:
--[=[
 
Lua support for the {{lang}}, {{lang-xx}}, and {{transltransliteration}} templates and replacement of various supporting templates.
 
]=]
 
require('Module:No globalsstrict');
 
local getArgs = require ('Module:Arguments').getArgs;
Line 105:
The return value nil causes the calling lang, lang_xx, or transl function to set args.italic according to the template's
defined default ('inherit' for {{lang}}, 'inherit' or 'italic' for {{lang-xx}} depending on
the individual template's requirements, 'italic' for {{transltransliteration}}) or to the value appropriate to |script=, if set ({{lang}}
and {{lang-xx}} only).
 
Line 414:
local category;
if 'TranslTransliteration' == template then
category = 'TranslTransliteration';
else
category = 'Lang and lang-xx'
Line 632:
return translit <i lang=xx-Latn>...</i> where xx is the language code; else return empty string
 
The value |script= is not used in {{transltransliteration}} for this purpose; instead it uses |code. Because language scripts
are listed in the {{transltransliteration}} switches they are included in the data tables. The script parameter is introduced
at {{Language with name and transliteration}}. If |script= is set, this function uses it in preference to code.
 
Line 643:
transl() always provides language_name, translit, and one of code or tscript, never both; always provides style
 
For {{transltransliteration}}, style only applies when a language code is provided
]]
 
Line 705:
 
local close_tag;
if is_set (code) then -- when a language code is provided (always with {{lang-xx}} templates, not always with {{transltransliteration}})
code = code:match ('^(%a%a%a?)'); -- strip all subtags leaving only the language subtag
 
if not style then -- nil for the default italic style
table.insert (out_t, "<i lang=\""); -- so use <i> tag
Line 716 ⟶ 718:
table.insert (out_t, "-Latn\">"); -- transliterations are always Latin script
else
table.insert (out_t, "<span>"); -- when no language code: no lang= attribute, not italic ({{transltransliteration}} only)
close_tag = '</span>';
end
Line 838 ⟶ 840:
If text contains <poem>...</poem> stripmarker, return text unmodified and choose <div>..</div> tags because
the stripmarker is replaced with text wrapped in <div>..</div> tags.
 
If the text contains any actual <div>...</div> tags, then it's again returned unmodified and <div>...</div>
tags are used to wrap it, to prevent div/span inversion.
 
]]
Line 846 ⟶ 851:
if has_poem_tag (text) then -- contains poem stripmarker (we can't know the content of that)
tag = 'div'; -- poem replacement is in div tags so lang must use div tags
elseif text:find ('<div') then -- reductive; if the text contains a div tag, we must use div tags
tag = 'div';
elseif mw.text.trim (text):find ('\n\n+') then -- contains implied p tags
text = mw.text.trim (text); -- trim leading and trailing whitespace characters
Line 935 ⟶ 942:
local template = args.template or 'Lang';
 
maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once
maint_msgs = {};
validate_cat_args (args); -- determine if categorization should be suppressed
 
Line 1,035 ⟶ 1,045:
 
return _lang (args);
end
 
 
--[[--------------------------< T R A N S L A T I O N _ M A K E >----------------------------------------------
 
stand-alone function to create literal translation of main text
 
Also used by {{lang-x2}}
 
]]
 
local function translation_make (args_t)
local translation_t = {', '}; -- initialize output
 
if 'none' ~= args_t.label then -- if we want a label
table.insert (translation_t, '<small>'); -- open the <small> html tag
if 'no' == argsargs_t.link then
table.insert (outtranslation_t, '<abbr title="literal translation">lit.</abbr>'); -- unlinked form
else
table.insert (outtranslation_t, make_wikilink ('Literal translation', 'lit.')); -- linked form
end
table.insert (outtranslation_t, "&thinsp;</small>"); -- close the <small> html tag
end
table.insert (outtranslation_t, table.concat ({'&#39;', argsargs_t.translation, '&#39;'})); -- use html entities to avoid wiki markup confusion
return table.concat (translation_t); -- make a big string and done
end
 
Line 1,096 ⟶ 1,131:
local template = args.template or 'Lang-xx';
 
maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once
maint_msgs = {};
if args[1] and args.text then
return make_error_msg ('conflicting: {{{1}}} and |text=', args, template);
Line 1,229 ⟶ 1,267:
if is_set (args.translation) then -- translation (not supported in {{lang}})
table.insert (out, ',translation_make '(args));
if 'none' ~= args.label then
table.insert (out, '<small>');
if 'no' == args.link then
table.insert (out, '<abbr title="literal translation">lit.</abbr>');
else
table.insert (out, make_wikilink ('Literal translation', 'lit.'));
end
table.insert (out, "&thinsp;</small>");
end
table.insert (out, table.concat ({'&#39;', args.translation, '&#39;'})); -- use html entities to avoid wiki markup confusion
end
Line 1,501 ⟶ 1,529:
local msg; -- for when called functions return an error message
 
maint_cats = {}; -- initialize because when this module required into another module, these only declared once so only initialzed once
if is_set (args[3]) then -- [3] set when {{transl|code|standard|text}}
maint_msgs = {};
if is_set (args[3]) then -- [3] set when {{transltransliteration|code|standard|text}}
args.text = args[3]; -- get the transliterated text
args.translit_std = args[2] and args[2]:lower(); -- get the standard; lower case for table indexing
 
if not title_table[args.translit_std] then
return make_error_msg (table.concat ({'unrecognized transliteration standard: ', args.translit_std}), args, 'TranslTransliteration');
end
else
if is_set (args[2]) then -- [2] set when {{transltransliteration|code|text}}
args.text = args[2]; -- get the transliterated text
else
if args[1] and (args[1]:match ('^%a%a%a?%a?$') thenor -- args[2] missing; is args[1] a codelanguage or script tag or is it the transliterated text?
return make_error_msgargs[1]:match ('no text', args, 'Transl^%a%a%a?%-x%-');) then -- or is args[1] is a code so we're missingprivate-use texttag
return make_error_msg ('no text', args, 'Transliteration'); -- args[1] is a code so we're missing text
else
args.text = args[1]; -- args[1] is not a code so we're missing that; assign args.text for error message
return make_error_msg ('missing language / script code', args, 'TranslTransliteration');
end
end
Line 1,522 ⟶ 1,554:
 
if is_set (args[1]) then -- IANA language code used for html lang= attribute; or ISO 15924 script code
if args[1]:match ('^%a%a%a?%a?$') or args[1]:match ('^%a%a%a?%-x%-') then -- args[1] has correct form?
args.code = args[1]:lower(); -- use the language/script code; only (2, 3, or 4 alpha characters) or private-use; lower case because table indexes are lower case
else
return make_error_msg (table.concat ({'unrecognized language / script code: ', args[1]}), args, 'TranslTransliteration'); -- invalid language / script code
end
else
return make_error_msg ('missing language / script code', args, 'TranslTransliteration'); -- missing language / script code so quit
end
 
args.italic, msg = validate_italic (args);
if msg then
return make_error_msg (msg, args, 'TranslTransliteration');
end
Line 1,542 ⟶ 1,574:
if override_table[args.code] then -- is code a language code defined in the override table?
language_name = override_table[args.code];
args.code = args.code:match ('^%a%a%a?'); -- if private use, strip all but language subtag
elseif lang_table[args.code] then -- is code a language code defined in the standard language code tables?
language_name = lang_table[args.code];
Line 1,551 ⟶ 1,584:
args.code = ''; -- unset because not a language code
else
return make_error_msg (table.concat ({'unrecognized language / script code: ', args.code}), args, 'TranslTransliteration'); -- invalid language / script code
end
-- here only when all parameters passed to make_translit() are valid
Line 1,630 ⟶ 1,663:
tag_from_name = tag_from_name, -- returns ietf tag associated with language name
name_from_tag = name_from_tag, -- used for template documentation; possible use in ISO 639 name from code templates
transl = transl, -- entry point for {{transltransliteration}}
_category_from_tag = _category_from_tag, -- entry points when this module is require()d into other modules
Line 1,641 ⟶ 1,674:
_name_from_tag = _name_from_tag,
_transl = _transl,
_translation_make = translation_make,
};
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu