Module:Lang: Difference between revisions
Content deleted Content added
Johnrdorazio (talk | contribs) m 1 revision imported |
thinsp after lit. per talk |
||
Line 127: | Line 127: | ||
if count > 1 then -- return nil and an error message if more than one is set |
if count > 1 then -- return nil and an error message if more than one is set |
||
return nil, 'only one of |
return nil, 'only one of |italic=, |italics=, or |i= can be specified'; |
||
end |
end |
||
Line 412: | Line 412: | ||
local category; |
local category; |
||
if ' |
if 'Transl' == template then |
||
category = ' |
category = 'Transl'; |
||
else |
else |
||
category = ' |
category = 'Lang and lang-xx' |
||
end |
end |
||
table.insert (out, table.concat ({' |
table.insert (out, table.concat ({'[', args.text or 'undefined', '] '})); -- for error messages output args.text if available |
||
table.insert (out, table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\"> |
table.insert (out, table.concat ({'<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: {{', template, '}}: '})); |
||
table.insert (out, msg); |
table.insert (out, msg); |
||
table.insert (out, table.concat ({' ([[:Category:', category, ' template errors|help]])'})); |
table.insert (out, table.concat ({' ([[:Category:', category, ' template errors|help]])'})); |
||
Line 517: | Line 517: | ||
if 'normal' == style then -- when |italic=no |
if 'normal' == style then -- when |italic=no |
||
table.insert (html, ' style=\"font-style:normal;'); -- override external markup, if any |
table.insert (html, ' style=\"font-style: normal;'); -- override external markup, if any |
||
style_added = '\"'; -- remember that style attribute added and is not yet closed |
style_added = '\"'; -- remember that style attribute added and is not yet closed |
||
end |
end |
||
Line 523: | Line 523: | ||
if is_set (size) then -- when |size=<something> |
if is_set (size) then -- when |size=<something> |
||
if is_set (style_added) then |
if is_set (style_added) then |
||
table.insert (html, table.concat ({' font-size:', size, ';'})); -- add when style attribute already inserted |
table.insert (html, table.concat ({' font-size: ', size, ';'})); -- add when style attribute already inserted |
||
else |
else |
||
table.insert (html, table.concat ({' style=\"font-size:', size, ';'})); -- create style attribute |
table.insert (html, table.concat ({' style=\"font-size: ', size, ';'})); -- create style attribute |
||
style_added = '\"'; -- remember that style attribute added and is not yet closed |
style_added = '\"'; -- remember that style attribute added and is not yet closed |
||
end |
end |
||
Line 535: | Line 535: | ||
table.insert (html, ' collective text'); -- for collective languages |
table.insert (html, ' collective text'); -- for collective languages |
||
else |
else |
||
table.insert (html, ' |
table.insert (html, '-language text'); -- for individual languages |
||
end |
end |
||
table.insert (html, '\">'); -- close the opening html tag |
table.insert (html, '\">'); -- close the opening html tag |
||
Line 561: | Line 561: | ||
for ISO 639-2 collective languages (and for 639-1 bh): |
for ISO 639-2 collective languages (and for 639-1 bh): |
||
[[Category:Articles with text |
[[Category:Articles with text in <language> languages]] |
||
]=] |
]=] |
||
Line 574: | Line 574: | ||
if language_name:find ('languages') then |
if language_name:find ('languages') then |
||
return table.concat ({'[[Category:Articles with text |
return table.concat ({'[[Category:Articles with text in ', language_name, ']]'}); |
||
-- return table.concat ({'[[Category:Articles with text from ', language_name, ']]'}); -- proposed version at Wikipedia:Categories_for_discussion/Log/2020_August_18#Category:Articles_with_text_from_the_Afro-Asiatic_languages_collective |
|||
end |
end |
||
Line 619: | Line 618: | ||
table.insert (tout, "<i lang=\""); -- so use <i> tag |
table.insert (tout, "<i lang=\""); -- so use <i> tag |
||
else |
else |
||
table.insert (tout, table.concat ({'<span style=\"font-style:', style, '\" lang=\"'})); -- non-standard style, construct a span tag for it |
table.insert (tout, table.concat ({'<span style=\"font-style: ', style, '\" lang=\"'})); -- non-standard style, construct a span tag for it |
||
end |
end |
||
table.insert (tout, code); |
table.insert (tout, code); |
||
Line 724: | Line 723: | ||
if 0 < #maint_msgs then -- when there are maintenance messages |
if 0 < #maint_msgs then -- when there are maintenance messages |
||
table.insert (maint, table.concat ({'<span class="lang-comment" style="font-style:normal; display:none; color:#33aa33; margin-left:0.3em">'})); -- opening <span> tag |
table.insert (maint, table.concat ({'<span class="lang-comment" style="font-style: normal; display: none; color: #33aa33; margin-left: 0.3em;">'})); -- opening <span> tag |
||
for _, msg in ipairs (maint_msgs) do |
for _, msg in ipairs (maint_msgs) do |
||
table.insert (maint, table.concat ({msg, ' '})); -- add message strings |
table.insert (maint, table.concat ({msg, ' '})); -- add message strings |
||
Line 891: | Line 890: | ||
local msg; -- for error messages |
local msg; -- for error messages |
||
local tag = 'span'; -- initial value for make_text_html() |
local tag = 'span'; -- initial value for make_text_html() |
||
local template = args.template or ' |
local template = args.template or 'Lang'; |
||
⚫ | |||
if args[1] and args.code then |
if args[1] and args.code then |
||
return make_error_msg ('conflicting: {{{1}}} and |
return make_error_msg ('conflicting: {{{1}}} and |code=', args, template); |
||
else |
else |
||
args.code = args[1] or args.code; -- prefer args.code |
args.code = args[1] or args.code; -- prefer args.code |
||
Line 900: | Line 901: | ||
if args[2] and args.text then |
if args[2] and args.text then |
||
return make_error_msg ('conflicting: {{{2}}} and |
return make_error_msg ('conflicting: {{{2}}} and |text=', args, template); |
||
else |
else |
||
args.text = args[2] or args.text; -- prefer args.text |
args.text = args[2] or args.text; -- prefer args.text |
||
Line 911: | Line 912: | ||
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate html tag with text trimmed accordingly |
args.text, tag = html_tag_select (args.text); -- inspects text; returns appropriate html tag with text trimmed accordingly |
||
⚫ | |||
args.rtl = args.rtl == 'yes'; -- convert to boolean: 'yes' -> true, other values -> false |
args.rtl = args.rtl == 'yes'; -- convert to boolean: 'yes' -> true, other values -> false |
||
Line 918: | Line 917: | ||
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag |
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag |
||
if msg then |
if msg then |
||
return make_error_msg (table.concat ({'invalid |
return make_error_msg (table.concat ({'invalid |proto=: ', args.proto}), args, template); |
||
end |
end |
||
Line 1,052: | Line 1,051: | ||
local msg; -- for error messages |
local msg; -- for error messages |
||
local tag = 'span'; -- initial value for make_text_html() |
local tag = 'span'; -- initial value for make_text_html() |
||
local template = args.template or ' |
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 |
return make_error_msg ('conflicting: {{{1}}} and |text=', args, template); |
||
else |
else |
||
args.text = args[1] or args.text; -- prefer args.text |
args.text = args[1] or args.text; -- prefer args.text |
||
Line 1,068: | Line 1,067: | ||
if args[2] and args.translit then |
if args[2] and args.translit then |
||
return make_error_msg ('conflicting: {{{2}}} and |
return make_error_msg ('conflicting: {{{2}}} and |translit=', args, template); |
||
else |
else |
||
args.translit = args[2] or args.translit -- prefer args.translit |
args.translit = args[2] or args.translit -- prefer args.translit |
||
Line 1,074: | Line 1,073: | ||
if args[3] and (args.translation or args.lit) then |
if args[3] and (args.translation or args.lit) then |
||
return make_error_msg ('conflicting: {{{3}}} and |
return make_error_msg ('conflicting: {{{3}}} and |lit= or |translation=', args, template); |
||
elseif args.translation and args.lit then |
elseif args.translation and args.lit then |
||
return make_error_msg ('conflicting: |
return make_error_msg ('conflicting: |lit= and |translation=', args, template); |
||
else |
else |
||
args.translation = args[3] or args.translation or args.lit; -- prefer args.translation |
args.translation = args[3] or args.translation or args.lit; -- prefer args.translation |
||
Line 1,082: | Line 1,081: | ||
if args.links and args.link then |
if args.links and args.link then |
||
return make_error_msg ('conflicting: |
return make_error_msg ('conflicting: |links= and |link=', args, template); |
||
else |
else |
||
args.link = args.link or args.links; -- prefer args.link |
args.link = args.link or args.links; -- prefer args.link |
||
Line 1,124: | Line 1,123: | ||
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag |
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag |
||
if msg then |
if msg then |
||
return make_error_msg (table.concat ({'invalid |
return make_error_msg (table.concat ({'invalid |proto=: ', args.proto}), args, template); |
||
end |
end |
||
Line 1,158: | Line 1,157: | ||
args.text = proto_prefix (args.text, language_name, args.proto); -- prefix proto-language text with a splat |
args.text = proto_prefix (args.text, language_name, args.proto); -- prefix proto-language text with a splat |
||
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.italic, args.size, nil)) |
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.italic, args.size, ('none' == args.label) and language_name or nil)) |
||
if is_set (args.translit) and not unicode.is_Latin (args.text) then -- transliteration (not supported in {{lang}}); not supported when args.text is wholly latn text (this is an imperfect test) |
if is_set (args.translit) and not unicode.is_Latin (args.text) then -- transliteration (not supported in {{lang}}); not supported when args.text is wholly latn text (this is an imperfect test) |
||
Line 1,195: | Line 1,194: | ||
table.insert (out, make_wikilink ('Literal translation', 'lit.')); |
table.insert (out, make_wikilink ('Literal translation', 'lit.')); |
||
end |
end |
||
table.insert (out, "& |
table.insert (out, " </small>"); |
||
end |
end |
||
table.insert (out, table.concat ({''', args.translation, '''})); -- use html entities to avoid wiki markup confusion |
table.insert (out, table.concat ({''', args.translation, '''})); -- use html entities to avoid wiki markup confusion |
||
Line 1,313: | Line 1,312: | ||
local function is_ietf_tag (frame) |
local function is_ietf_tag (frame) |
||
return _is_ietf_tag (getArgs(frame)[1]); -- args[1] is the ietf language tag to be tested; |
return _is_ietf_tag (getArgs (frame)[1]); -- args[1] is the ietf language tag to be tested; also get parent frame |
||
end |
|||
--[[--------------------------< I S _ I E T F _ T A G _ F R A M E >-------------------------------------------- |
|||
Module entry point from an {{#invoke:}}; same as is_ietf_tag() except does not get parameters from the parent |
|||
(template) frame. This function not useful when called by {{lang|fn=is_ietf_tag_frame|<tag>}} because <tag> |
|||
is in the parent frame. |
|||
]] |
|||
local function is_ietf_tag_frame (frame) |
|||
return _is_ietf_tag (getArgs (frame, {frameOnly = true,})[1]); -- args[1] is the ietf language tag to be tested; do not get parent frame |
|||
end |
end |
||
Line 1,341: | Line 1,353: | ||
if msg then |
if msg then |
||
local template = (args['template'] and table.concat ({'{{', args['template'], '}}: '})) or ''; -- make template name (if provided by the template) |
local template = (args['template'] and table.concat ({'{{', args['template'], '}}: '})) or ''; -- make template name (if provided by the template) |
||
return table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\"> |
return table.concat ({'<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ', template, msg, '</span>'}); |
||
end |
end |
||
Line 1,405: | Line 1,417: | ||
template = table.concat ({'{{', args['template'], '}}: '}); -- make template name (if provided by the template) |
template = table.concat ({'{{', args['template'], '}}: '}); -- make template name (if provided by the template) |
||
end |
end |
||
return table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\"> |
return table.concat ({'<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ', template, msg, '</span>'}); |
||
end |
end |
||
Line 1,442: | Line 1,454: | ||
local title_table = lang_data.translit_title_table; -- table of transliteration standards and the language codes and scripts that apply to those standards |
local title_table = lang_data.translit_title_table; -- table of transliteration standards and the language codes and scripts that apply to those standards |
||
local language_name; -- language name that matches language code; used for tool tip |
local language_name; -- language name that matches language code; used for tool tip |
||
local translit; -- |
local translit; -- transliterated text to display |
||
local script; -- IANA script |
local script; -- IANA script |
||
local msg; -- for when called functions return an error message |
local msg; -- for when called functions return an error message |
||
Line 1,451: | Line 1,463: | ||
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 |
||
Line 1,458: | Line 1,470: | ||
else |
else |
||
if args[1] and args[1]:match ('^%a%a%a?%a?$') then -- args[2] missing; is args[1] a code or its it the transliterated text? |
if args[1] and args[1]:match ('^%a%a%a?%a?$') then -- args[2] missing; is args[1] a code or its it the transliterated text? |
||
return make_error_msg ('no text', args, ' |
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,470: | Line 1,482: | ||
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 |
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,496: | Line 1,508: | ||
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,536: | Line 1,548: | ||
if msg then |
if msg then |
||
local template = (args['template'] and table.concat ({'{{', args['template'], '}}: '})) or ''; -- make template name (if provided by the template) |
local template = (args['template'] and table.concat ({'{{', args['template'], '}}: '})) or ''; -- make template name (if provided by the template) |
||
return table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\"> |
return table.concat ({'<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: ', template, msg, '</span>'}); |
||
end |
end |
||
Line 1,567: | Line 1,579: | ||
lang_xx_italic = lang_xx_italic, |
lang_xx_italic = lang_xx_italic, |
||
is_ietf_tag = is_ietf_tag, |
is_ietf_tag = is_ietf_tag, |
||
is_ietf_tag_frame = is_ietf_tag_frame, |
|||
is_lang_name = is_lang_name, |
is_lang_name = is_lang_name, |
||
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 |
||
Line 1,577: | Line 1,590: | ||
_lang_xx_italic = _lang_xx_italic, |
_lang_xx_italic = _lang_xx_italic, |
||
_is_ietf_tag = _is_ietf_tag, |
_is_ietf_tag = _is_ietf_tag, |
||
get_ietf_parts = get_ietf_parts, |
|||
_tag_from_name = _tag_from_name, |
_tag_from_name = _tag_from_name, |
||
_name_from_tag = _name_from_tag, |
_name_from_tag = _name_from_tag, |