Module:Lang/utilities
require('strict');
local getArgs = require ('Module:Arguments').getArgs;
local unicode = require ("Module:Unicode data"); -- for is_latin()
local lang = require ('Module:Lang');
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local err_texts = { -- because wrapper templates have Latn/non-Latn text ordered according to the wrapper template's name
['lang-sh-cyrl-latn'] = true, -- this template has |1=cyrl script |2=latn script
}
--[[--------------------------< E R R O R _ M S G _ M A K E >--------------------------------------------------
assembles an error message from template name, message text, help link, and error category.
{{', template, '}}
]]
local function error_msg_make (msg, template, nocat)
local out = {};
local category = 'Lang and lang-xx';
table.insert (out, table.concat ({'Error: {{', template, '}}: '}));
table.insert (out, msg);
table.insert (out, table.concat ({' (help)'}));
table.insert (out, '');
if (0 == namespace or 10 == namespace) and not nocat then -- categorize in article space (and template space to take care of broken usages)
table.insert (out, table.concat ({'Category:Lang and lang-xx template errors'}));
end
return table.concat (out);
end
--[[--------------------------< S E P A R A T O R _ G E T >----------------------------------------------------
allowed separators are comma, semicolon, virgule, or a quoted string of text
]]
local function separator_get (sep_param_val)
if not sep_param_val then return ', ' end; -- not specified, use default
if ',' == sep_param_val then return ', ' end;
if ';' == sep_param_val then return '; ' end;
if '/' == sep_param_val then return '/' end;
local str;
if sep_param_val:match ('^%b\"\"$') then -- if quoted string and uses double quotes
str = sep_param_val:match ('%b\"\"'):gsub ('^"', ):gsub ('"$', );
return str; -- return the contents of the quote
elseif sep_param_val:match ('^%b\'\'$') then -- if quoted string and uses single quotes
str = sep_param_val:match ('%b\'\):gsub ('^\, ):gsub ('\'$', );
return str; -- return the contents of the quote
end
return ', '; -- default in case can't extract quoted string
end
--[[--------------------------< P A R A M _ S E L E C T >------------------------------------------------------
Selects the appropriate enumerated parameters for
]]
local function param_select (args_t, lang_args_t, lang_xx_args_t, swap)
local enum_xx = swap and '2' or '1';
local enum = swap and '1' or '2';
lang_xx_args_t.script = args_t['script' .. enum_xx]; -- these for
lang_xx_args_t.region = args_t['region' .. enum_xx];
lang_xx_args_t.variant = args_t['variant' .. enum_xx];
lang_xx_args_t.italic = args_t['italic' .. enum_xx];
lang_xx_args_t.size = args_t['size' .. enum_xx];
lang_args_t.italic = args_t['italic' .. enum]; -- these for
lang_args_t.size = args_t['size' .. enum];
end
--[[--------------------------< I E T F _ T A G _ M A K E >----------------------------------------------------
make ietf tag for _lang() (second rendered
]]
local function ietf_tag_make (args_t, tag, swap)
local ietf_tag_t = {tag}; -- initialize with
local enum = swap and '1' or '2'; -- when
for _, param in ipairs ({'script'..enum, 'region'..enum, 'variant'..enum}) do
if args_t[param] then table.insert (ietf_tag_t, args_t[param]) end -- build
end
return table.concat (ietf_tag_t, '-'); -- concatenate subtags with hyphen separator and done
end
--[[--------------------------< _ L A N G _ X 2 >--------------------------------------------------------------
mimics {{lang|
Latin-script form). Intended for languages where two scripts are 'official' or 'native and equal in status' (sh
is and sr may be a candidate for this; are there others?)
{{lang_x2|