Module:Lang: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 437:
function p.lang (frame)
local args = getArgs(frame);
if args[1] and args.code then
return make_error_msg ('{{lang}}: conflicting: {{{1}}} and |code=', args.nocat);
else
args.code = args[1] or args.code;
end
 
if args[2] and args.text then
return make_error_msg ('{{lang}}: conflicting: {{{2}}} and |text=', args.nocat);
else
args.text = args[2] or args.text;
end
local out = {};
local language_name;
local subtags = {};
local code, script, region, variant = get_ietf_parts (args.code or args[1]);
local code;
 
local code, subtags.script, subtags.region, subtags.variant = get_ietf_parts (args.code or args[1]);
if not (code and subtags.script and subtags.region and subtags.variant) then
return make_error_msg (table.concat ({'{{lang}}: unknown language code: ', args.code or args[1] or 'missing'}), args.nocat);
end
 
if not is_set (argssubtags.italicvariant) then -- special case test for |variant=
if not in_array (code, lang_name_table.variant[subtags.variant]['prefixes']) then
args.italic = 'no'; -- DEFAULT for {{lang}} templates is to not italicize
return make_error_msg (table.concat ({'{{lang}}: invalid code-variant combination: ', code, '-', subtags.variant}), args.nocat);
end
end
 
if not is_set (args.italic) then -- args.italic controls
local msg = validate_text ('lang', args);
if 'latn' == subtags.script then -- script set to latn
if is_set (msg) then
args.italic = 'noyes'; -- DEFAULT for {{lang}} templates is toupright; but if notlatn italicizescript
return msg;
else
args.italic = 'no'; -- italic not set; script not latn
end
end
args.code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant); -- format to recommended subtag styles
 
if lang_data.override[code] then
Line 515 ⟶ 535:
args.text = args[1] or args.text;
end
 
if args[2] and args.translit then
return make_error_msg ('{{lang-xx}}: conflicting: {{{2}}} and |translit=', args.nocat);
Anonymous user