Editing Module:Lang
Jump to navigation
Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
--[=[ | --[=[ | ||
Lua support for the {{lang}}, {{lang-xx}}, and {{ | Lua support for the {{lang}}, {{lang-xx}}, and {{transl}} templates and replacement of various supporting templates. | ||
]=] | ]=] | ||
require(' | require('Module:No globals'); | ||
local getArgs = require ('Module:Arguments').getArgs; | local getArgs = require ('Module:Arguments').getArgs; | ||
Line 105: | Line 105: | ||
The return value nil causes the calling lang, lang_xx, or transl function to set args.italic according to the template's | 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 | defined default ('inherit' for {{lang}}, 'inherit' or 'italic' for {{lang-xx}} depending on | ||
the individual template's requirements, 'italic' for {{ | the individual template's requirements, 'italic' for {{transl}}) or to the value appropriate to |script=, if set ({{lang}} | ||
and {{lang-xx}} only). | and {{lang-xx}} only). | ||
Line 414: | Line 414: | ||
local category; | local category; | ||
if ' | if 'Transl' == template then | ||
category = ' | category = 'Transl'; | ||
else | else | ||
category = 'Lang and lang-xx' | category = 'Lang and lang-xx' | ||
Line 632: | Line 632: | ||
return translit <i lang=xx-Latn>...</i> where xx is the language code; else return empty string | return translit <i lang=xx-Latn>...</i> where xx is the language code; else return empty string | ||
The value |script= is not used in {{ | The value |script= is not used in {{transl}} for this purpose; instead it uses |code. Because language scripts | ||
are listed in the {{ | are listed in the {{transl}} 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. | at {{Language with name and transliteration}}. If |script= is set, this function uses it in preference to code. | ||
Line 643: | Line 643: | ||
transl() always provides language_name, translit, and one of code or tscript, never both; always provides style | transl() always provides language_name, translit, and one of code or tscript, never both; always provides style | ||
For {{ | For {{transl}}, style only applies when a language code is provided | ||
]] | ]] | ||
Line 705: | Line 705: | ||
local close_tag; | local close_tag; | ||
if is_set (code) then -- when a language code is provided (always with {{lang-xx}} templates, not always with {{ | if is_set (code) then -- when a language code is provided (always with {{lang-xx}} templates, not always with {{transl}}) | ||
if not style then -- nil for the default italic style | if not style then -- nil for the default italic style | ||
table.insert (out_t, "<i lang=\""); -- so use <i> tag | table.insert (out_t, "<i lang=\""); -- so use <i> tag | ||
Line 718: | Line 716: | ||
table.insert (out_t, "-Latn\">"); -- transliterations are always Latin script | table.insert (out_t, "-Latn\">"); -- transliterations are always Latin script | ||
else | else | ||
table.insert (out_t, "<span>"); -- when no language code: no lang= attribute, not italic ({{ | table.insert (out_t, "<span>"); -- when no language code: no lang= attribute, not italic ({{transl}} only) | ||
close_tag = '</span>'; | close_tag = '</span>'; | ||
end | end | ||
Line 840: | Line 838: | ||
If text contains <poem>...</poem> stripmarker, return text unmodified and choose <div>..</div> tags because | 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. | the stripmarker is replaced with text wrapped in <div>..</div> tags. | ||
]] | ]] | ||
Line 851: | Line 846: | ||
if has_poem_tag (text) then -- contains poem stripmarker (we can't know the content of that) | 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 | tag = 'div'; -- poem replacement is in div tags so lang must use div tags | ||
elseif mw.text.trim (text):find ('\n\n+') then -- contains implied p tags | elseif mw.text.trim (text):find ('\n\n+') then -- contains implied p tags | ||
text = mw.text.trim (text); -- trim leading and trailing whitespace characters | text = mw.text.trim (text); -- trim leading and trailing whitespace characters | ||
Line 942: | Line 935: | ||
local template = args.template or 'Lang'; | local template = args.template or 'Lang'; | ||
validate_cat_args (args); -- determine if categorization should be suppressed | validate_cat_args (args); -- determine if categorization should be suppressed | ||
Line 1,045: | Line 1,035: | ||
return _lang (args); | return _lang (args); | ||
end | end | ||
Line 1,131: | Line 1,096: | ||
local template = args.template or 'Lang-xx'; | local template = args.template or 'Lang-xx'; | ||
if args[1] and args.text then | if args[1] and args.text then | ||
return make_error_msg ('conflicting: {{{1}}} and |text=', args, template); | return make_error_msg ('conflicting: {{{1}}} and |text=', args, template); | ||
Line 1,267: | Line 1,229: | ||
if is_set (args.translation) then -- translation (not supported in {{lang}}) | if is_set (args.translation) then -- translation (not supported in {{lang}}) | ||
table.insert (out, | table.insert (out, ', '); | ||
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, " </small>"); | |||
end | |||
table.insert (out, table.concat ({''', args.translation, '''})); -- use html entities to avoid wiki markup confusion | |||
end | end | ||
Line 1,529: | Line 1,501: | ||
local msg; -- for when called functions return an error message | local msg; -- for when called functions return an error message | ||
if is_set (args[3]) then -- [3] set when {{transl|code|standard|text}} | |||
if is_set (args[3]) then -- [3] set when {{ | |||
args.text = args[3]; -- get the transliterated 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 | 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 | if not title_table[args.translit_std] then | ||
return make_error_msg (table.concat ({'unrecognized transliteration standard: ', args.translit_std}), args, ' | return make_error_msg (table.concat ({'unrecognized transliteration standard: ', args.translit_std}), args, 'Transl'); | ||
end | end | ||
else | else | ||
if is_set (args[2]) then -- [2] set when {{ | if is_set (args[2]) then -- [2] set when {{transl|code|text}} | ||
args.text = args[2]; -- get the transliterated text | args.text = args[2]; -- get the transliterated text | ||
else | else | ||
if args[1] and | if args[1] and args[1]:match ('^%a%a%a?%a?$') then -- args[2] missing; is args[1] a code or is it the transliterated text? | ||
return make_error_msg ('no text', args, 'Transl'); -- args[1] is a code so we're missing text | |||
else | else | ||
args.text = args[1]; -- args[1] is not a code so we're missing that; assign args.text for error message | 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, ' | return make_error_msg ('missing language / script code', args, 'Transl'); | ||
end | end | ||
end | end | ||
Line 1,554: | Line 1,522: | ||
if is_set (args[1]) then -- IANA language code used for html lang= attribute; or ISO 15924 script code | 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?$ | if args[1]:match ('^%a%a%a?%a?$') then -- args[1] has correct form? | ||
args.code = args[1]:lower(); -- use the language/script code; only (2, 3, or 4 alpha characters) | args.code = args[1]:lower(); -- use the language/script code; only (2, 3, or 4 alpha characters); lower case because table indexes are lower case | ||
else | else | ||
return make_error_msg (table.concat ({'unrecognized language / script code: ', args[1]}), args, ' | return make_error_msg (table.concat ({'unrecognized language / script code: ', args[1]}), args, 'Transl'); -- invalid language / script code | ||
end | end | ||
else | else | ||
return make_error_msg ('missing language / script code', args, ' | return make_error_msg ('missing language / script code', args, 'Transl'); -- missing language / script code so quit | ||
end | end | ||
args.italic, msg = validate_italic (args); | args.italic, msg = validate_italic (args); | ||
if msg then | if msg then | ||
return make_error_msg (msg, args, ' | return make_error_msg (msg, args, 'Transl'); | ||
end | end | ||
Line 1,574: | Line 1,542: | ||
if override_table[args.code] then -- is code a language code defined in the override table? | if override_table[args.code] then -- is code a language code defined in the override table? | ||
language_name = override_table[args.code]; | language_name = override_table[args.code]; | ||
elseif lang_table[args.code] then -- is code a language code defined in the standard language code tables? | elseif lang_table[args.code] then -- is code a language code defined in the standard language code tables? | ||
language_name = lang_table[args.code]; | language_name = lang_table[args.code]; | ||
Line 1,584: | Line 1,551: | ||
args.code = ''; -- unset because not a language code | args.code = ''; -- unset because not a language code | ||
else | else | ||
return make_error_msg (table.concat ({'unrecognized language / script code: ', args.code}), args, ' | return make_error_msg (table.concat ({'unrecognized language / script code: ', args.code}), args, 'Transl'); -- invalid language / script code | ||
end | end | ||
-- here only when all parameters passed to make_translit() are valid | -- here only when all parameters passed to make_translit() are valid | ||
Line 1,663: | Line 1,630: | ||
tag_from_name = tag_from_name, -- returns ietf tag associated with language name | 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 | name_from_tag = name_from_tag, -- used for template documentation; possible use in ISO 639 name from code templates | ||
transl = transl, -- entry point for {{ | transl = transl, -- entry point for {{transl}} | ||
_category_from_tag = _category_from_tag, -- entry points when this module is require()d into other modules | _category_from_tag = _category_from_tag, -- entry points when this module is require()d into other modules | ||
Line 1,674: | Line 1,641: | ||
_name_from_tag = _name_from_tag, | _name_from_tag = _name_from_tag, | ||
_transl = _transl, | _transl = _transl, | ||
}; | }; |