Anonymous user
Module:Lang: Difference between revisions
fix transl bug when |script= has a valid value;
Johnrdorazio (talk | contribs) m (1 revision imported) |
(fix transl bug when |script= has a valid value;) |
||
Line 706: | Line 706: | ||
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 {{transl}}) | if is_set (code) then -- when a language code is provided (always with {{lang-xx}} templates, not always with {{transl}}) | ||
code = code:match ('^(%a%a%a?)'); -- strip all subtags leaving only the language subtag | |||
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 1,536: | Line 1,538: | ||
args.text = args[2]; -- get the transliterated text | args.text = args[2]; -- get the transliterated text | ||
else | else | ||
if args[1] and args[1]:match ('^%a%a%a?%a?$') | if args[1] and (args[1]:match ('^%a%a%a?%a?$') or -- args[2] missing; is args[1] a language or script tag or is it the transliterated text? | ||
return make_error_msg ('no text', args, 'Transl'); | args[1]:match ('^%a%a%a?%-x%-')) then -- or is args[1] a private-use tag | ||
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 | ||
Line 1,546: | Line 1,549: | ||
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?$') then | 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); 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) or private-use; lower case because table indexes are lower case | ||
else | else | ||
return make_error_msg (table.concat ({'unrecognized language / script code: ', args[1]}), args, 'Transl'); -- invalid language / script code | return make_error_msg (table.concat ({'unrecognized language / script code: ', args[1]}), args, 'Transl'); -- invalid language / script code | ||
Line 1,566: | Line 1,569: | ||
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]; | ||
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? | 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]; |