Module:Lang: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 381:
args.text = args.text:gsub ("[^\']+\'$", "%1<span></span>"); -- trailing single quote mark
end
end
 
 
--[[--------------------------< S U B T A G _ C H E C K >------------------------------------------------------
 
checks the subtags: script, region, and variant to be valid and in agreement with any tags that are included in
the main language code: if |script=Cyrl and language code is 'abq-Cyrl' the two script must agree (case insensitive)
 
returns the selected subtag and nil error message;
returns empty string and nil error message when both language code subtag and matching subtag parameter are not set
returns nil and error message else
 
]]
 
local function subtag_check (name, args_code, code_subtag, args_subtag, nocat)
 
if not is_set (code_subtag) and not is_set (args_subtag) then -- no subtags, then bale
return ''; -- empty string for concatenation
end
args.scriptargs_subtag = args.scriptargs_subtag and args.scriptargs_subtag:lower(); -- so we only need do this once; prettify later
if not is_set (scriptcode_subtag) then -- if no ietf script subtag in args.code
if is_set (args.scriptargs_subtag) then -- and if |script<name>= has a value
if lang_name_table.script[args.scriptname][args_subtag] then -- and that value is legitimate script subtag
scriptcode_subtag = args.scriptargs_subtag; -- then use |script<name>=
else
return nil, make_error_msg (table.concat ({'{{lang-xx}}: invalid script' .. name .. ': ', args.scriptargs_subtag}), args.nocat);
end
end
else -- here when language code has a subtag
if is_set (args_subtag) and (code_subtag ~= args_subtag) then -- if there is a subtag parameter then it must match
return nil, make_error_msg (table.concat ({'{{lang-xx}}: code / script' .. name .. ' mismatch: ', args.codeargs_code:lower(), ' / ', args.scriptargs_subtag}), args.nocat);
end
end
 
return code_subtag;
end
 
Line 432 ⟶ 468:
--[[--------------------------< L A N G _ X X >----------------------------------------------------------------
 
<includeonly>{{#invoke:lang|lang_xx
<includeonly>{{#invoke:lang|lang_xx|code=<code>|script={{{script|}}}|text={{{1|}}}|link={{{links|{{{link}}}}}}|rtl={{{rtl|}}}|nocat={{{nocat|}}}|italic={{{italic|}}}|translation={{{lit|}}}|translit={{{translit|}}}|translit-script={{{translit-script|}}}|translit-std={{{translit-std|}}}}}</includeonly>
|code=<code>
|script={{{script|}}}
|region={{{region|}}}
|variant={{{variant|}}}
|text={{{1|}}}
|link={{{links|{{{link}}}}}}
|rtl={{{rtl|}}}
|nocat={{{nocat|}}}
|italic={{{italic|}}}
|translation={{{lit|}}}
|translit={{{translit|}}}
|translit-script={{{translit-script|}}}
|translit-std={{{translit-std|}}}}}</includeonly>
 
|code = (required) the BCP47 language code
Line 447 ⟶ 496:
|translit-std = the standard that applies to the transliteration
|translit-script = ISO 15924 script name; falls back to code
 
use of |script=
default state of |italic= for {{lang-xx}} is 'yes' - this presumes that Latn is the script for |text=
 
]]
Line 462 ⟶ 506:
local out = {};
local language_name;
local subtags = {};
local code, script, region, variant = get_ietf_parts (args.code);
local code;
 
local translit_script;
local translit;
local translit_title;
 
local code, subtags.script, subtags.region, subtags.variant = get_ietf_parts (args.code);
if not (code and subtags.script and subtags.region and subtags.variant) then
return make_error_msg (table.concat ({'{{lang-xx}}: unknown language code: ', args.code or 'missing'}), args.nocat);
end
local msg = validate_text ('lang-xx', args); -- ensure that |text= is set, does not contain italic markup and is protected from improper bolding
if is_set (msg) then
return msg;
end
 
for name, value in pairs (subtags) do -- spin through the subtags table and consolidate code and parameter-provided language subtags
args.script = args.script and args.script:lower(); -- so we only need do this once; prettify later
subtags[name], msg = subtag_check (name, args.code, value, args[name], args.nocat);
if not is_set (script) then -- if no ietf script subtag in args.code
if not subtags[name] then
if is_set (args.script) then -- and if |script= has a value
return msg; -- some sort of error detected, return the error message
if lang_name_table.script[args.script] then -- and that value is legitimate script subtag
script = args.script; -- then use |script=
else
return make_error_msg (table.concat ({'{{lang-xx}}: invalid script: ', args.script}), args.nocat);
end
end
else
if is_set (args.script) and (script ~= args.script) then
return make_error_msg (table.concat ({'{{lang-xx}}: code / script mismatch: ', args.code:lower(), ' / ', args.script}), args.nocat);
end
end
 
if not is_set (args.italic) then -- args.italic controls
if not is_set (subtags.script) or ('latn' == subtags.script) then -- script not set then default; script set to latn same
args.italic = 'yes'; -- DEFAULT for {{lang-xx}} templates is to italicize
else
Line 500 ⟶ 539:
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 532 ⟶ 571:
table.insert (out, translit);
else
return make_error_msg (table.concat ({'{{lang-xx}}: invalid translit-std: \'', args['translit-std'] or 'missing', '\' or transli-script: \'', args['translit-script'] or 'missing', '\''}), args.nocat);
end
end
Anonymous user