Module:Lang: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
Line 340: Line 340:
table.insert (tout, "</span>''");
table.insert (tout, "</span>''");
return table.concat (tout);
return table.concat (tout);
end


--[[--------------------------< V A L I D A T E _ T E X T >---------------------------------------------------

]]

local function validate_text (template, args)
if not is_set (args.text) then
return make_error_msg (table.concat ({'{{', template, '}}: no text'}), args.nocat);
end

if args.text:find ("\'\'\'\'\'[\']+") then
return make_error_msg (table.concat ({'{{', template, '}}: text has malformed markup'}), args.nocat);
end

if args.text:match ("%f[\']\'\'[^\']+\'\'%f[^\']") or args.text:match ("\'\'\'\'\'[^\']+\'\'\'\'\'") then -- italic but not bold or bold italic
return make_error_msg (table.concat ({'{{', template, '}}: text has italic markup'}), args.nocat);
end

if args.text:find ("\'\'\'\'") then -- four apostrophes
return make_error_msg (table.concat ({'{{', template, '}}: text has malformed markup'}), args.nocat);
end

if 'yes' == args.italic then
if args.text:sub(1,1) == "'" then
args.text = "<span></span>" .. args.text;
end

if args.text:sub(-1,-1) == "'" then
args.text = args.text .. "<span></span>";
end
end
end
end


Line 363: Line 396:
if not (code and script and region and variant) then
if not (code and script and region and variant) then
return make_error_msg (table.concat ({'{{lang}}: unknown language code: ', args.code or 'missing'}), args.no_cat);
return make_error_msg (table.concat ({'{{lang}}: unknown language code: ', args.code or 'missing'}), args.nocat);
end
end
if not is_set (args.text) then
return make_error_msg ('{{lang}}: no text', args.no_cat);
end

if not is_set (args.italic) then
if not is_set (args.italic) then
args.italic = 'no'; -- DEFAULT for {{lang}} templates is to not italicize
args.italic = 'no'; -- DEFAULT for {{lang}} templates is to not italicize
end
end


local msg = validate_text ('lang', args);
if args.text:match ("%f[\']\'\'[^\']+\'\'%f[^\']") or args.text:match ("\'\'\'\'\'[^\']+\'\'\'\'\'") then -- italic but not bold or bold italic
if is_set (msg) then
return make_error_msg ('{{lang-xx}}: text has italic markup', args.no_cat);
return msg;
end
end
args.code = format_ietf_tag (code, script, region, variant); -- format to recommended subtag styles
args.code = format_ietf_tag (code, script, region, variant); -- format to recommended subtag styles


Line 429: Line 459:
if not (code and script and region and variant) then
if not (code and script and region and variant) then
return make_error_msg (table.concat ({'{{lang-xx}}: unknown language code: ', args.code or 'missing'}), args.no_cat);
return make_error_msg (table.concat ({'{{lang-xx}}: unknown language code: ', args.code or 'missing'}), args.nocat);
end
end
local msg = validate_text ('lang-xx', args);
if not is_set (args.text) then
if is_set (msg) then
return make_error_msg ('{{lang-xx}}: no text', args.no_cat);
return msg;
end

----------
if args.text:find ("\'\'\'\'\'[\']+") then
return make_error_msg ('{{lang-xx}}: text has malformed markup', args.no_cat);
end

if args.text:match ("%f[\']\'\'[^\']+\'\'%f[^\']") or args.text:match ("\'\'\'\'\'[^\']+\'\'\'\'\'") then -- italic but not bold or bold italic
return make_error_msg ('{{lang-xx}}: text has italic markup', args.no_cat);
end

if args.text:find ("\'\'\'\'") then -- four apostrophes
return make_error_msg ('{{lang-xx}}: text has malformed markup', args.no_cat);
end

if 'yes' == args.italic then
if args.text:sub(1,1) == "'" then
args.text = "<span></span>" .. args.text;
end

if args.text:sub(-1,-1) == "'" then
args.text = args.text .. "<span></span>";
end
end
end
----------


args.code = format_ietf_tag (code, script, region, variant); -- format to recommended subtag styles
args.code = format_ietf_tag (code, script, region, variant); -- format to recommended subtag styles