Module:Lang: Difference between revisions

+|label= support;
(remove deprecated entry point;)
(+|label= support;)
Line 39:
 
For the purposes of this function, Latn script is characters less control characters from these Unicode 10.0 Character Code Charts:
[http://www.unicode.org/charts/PDF/U0000.pdf C0 Controls and Basic Latin] U+0020–U+007E (20 - 7E) + see note about <poem>...</poem> support
[http://www.unicode.org/charts/PDF/U0080.pdf C1 Controls and Latin-1 Supplement] U+00A0-U+00AC, U+00C0–U+00FF (C2 A0 - C2 AC, C3 80 - C3 BF: \194\160-\194\172)
[http://www.unicode.org/charts/PDF/U0100.pdf Latin Extended-A] U+0100–U+017F (C4 80 - C5 BF)
Line 54:
[http://www.unicode.org/charts/PDF/U0250.pdf IPA Extensions] U+0250-U+02AF (C9 90 - CA AF)
[http://www.unicode.org/charts/PDF/U1D80.pdf Phonetic Extensions Supplement] U+1D80-U+1DBF (E1 B6 80 - E1 B6 BF)
 
{{lang}} is used inside <poem>...</poem> tags for song lyrics, poetry, etc. <poem>...</poem> replaces newlines with
poem stripmarkers. These have the form:
?'"`UNIQ--poem-67--QINU`"'?
where the '?' character is actually the delete character (U+007F, \127). Including the '\n' (U+0010) and 'del' (U+007F)
characters in the latn character table allows {{lang}} to auto-italicize text within <poem>...</poem> tags.
 
]]
Line 61 ⟶ 67:
{
'[', -- this is a set so include opening bracket
'\n\32-\126127', -- C0 Controls and Basic Latin U+0020–U+007E (20 - 7E) + (U+0010 and U+007F <poem>...</poem> support)
'\194\160-\194\172', -- C1 Controls and Latin-1 Supplement U+00A0-U+00AC (C2 A0 - C2 AC)
'\195\128-\195\191', -- (skip shy) U+00C0–U+00FF (C3 80 - C3 BF)
Line 343 ⟶ 349:
local out = {};
table.insert (out, table.concat ({'&#x5B;', args.text or 'undefined', '&#x5D; '})); -- for error messages output args.text if available
table.insert (out, '<span style="font-size:100%; font-style:normal;" class="error">error: ');
table.insert (out, msg);
table.insert (out, ' ([[:Category:lang and lang-xx template errors|help]])')
Line 485 ⟶ 491:
local title_table = lang_data.translit_title_table; -- table of transliteration standards and the language codes and scripts that apply to those standards
if is_set (code) then
table.insert (tout, "<i lang=\"");
table.insert (tout, code);
table.insert (tout, "-Latn\" title=\""); -- transliterations are always Latin script
else
table.insert (tout, "<i title=\""); -- no language code, no lang= attribute ({{transl}} only)
end
if not is_set (std) and not is_set (tscript) then -- when neither standard nor script specified
Line 496 ⟶ 506:
table.insert (tout, title_table[std][tscript]); -- add the appropriate text to the tool tip
else
table.insert (tout, title_table[std]['default']); -- use the default if script not in std table
return ''; -- one or both invalid, set up for an error message
end
elseif is_set (std) then -- translit-script not set, use language code
if not title_table[std] then return ''; end -- invalid standard, setuptsetup for error message
if title_table[std][code] then
Line 524 ⟶ 534:
 
 
--[=[--------------------------< V A L I D A T E _ T E X T >---------------------------------------------------
 
This function checks the content of args.text and returns empty string if nothing is amiss else it returns an
Line 532 ⟶ 542:
either as ''itself''' or as '''''bold italic'''''.
 
]=]
Also protects single leading and trailing single quote marks from being converted to bold by the addition of
adjacent italic markup.
 
]]
 
local function validate_text (template, args)
if not is_set (args.text) then
return make_error_msg (table.concat ({'{{', template, '}}: no text'}), args);
end
 
if args.text:find ("%f[\']\'\'\'\'%f[^\']") or args.text:find ("\'\'\'\'\'[\']+") then -- because we're looking, look for 4 appostrophes or 6+ appostrophes
return make_error_msg (table.concat ({'{{', template, '}}: text has malformed markup'}), args);
end
 
if 'lang-xx' == template then -- for the time being, this error checking does not apply to {{lang}}
if 'unset' ~= args.text:find ("\'\'\'\'\'[\']+")italic then -- because we're looking,allow lookitalic formarkup 6+when appostrophes|italic=unset
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 malformed markup'}), args);
return make_error_msg (table.concat ({'{{', template, '}}: text has italic markup'}), args);
end
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);
end
if args.text:find ("\'\'\'\'") then -- because we're looking, look for 4 apostrophes
return make_error_msg (table.concat ({'{{', template, '}}: text has malformed markup'}), args);
end
end
Line 678 ⟶ 683:
 
return table.concat (out); -- put it all together and done
end
 
 
Line 691 ⟶ 696:
 
For normal, upright style:
<includeonly>{{#invoke:lang|lang_xx_normallang_xx_inherit|code=xx}}</includeonly>
For italic style:
<includeonly>{{#invoke:lang|lang_xx_italic|code=xx}}</includeonly>
Line 708 ⟶ 713:
|italic = boolean true ('yes') renders displayed text in italic font; boolean false ('no') renders displayed text in normal font; not set renders according to initial_style_state
|lit = text that is a literal translation of text
|label = 'none' to suppress all labeling (language name, 'translit.', 'lit.')
any other text replaces language-name label - automatic wikilinking disabled
for those {{lang-xx}} templates that support transliteration: -- TODO:(those figuretemplate outwhere how|text= tois determineentirely iflatn transliteration is allowed/appropriatescript):
|translit = text that is a transliteration of text
|translit-std = the standard that applies to the transliteration
Line 813 ⟶ 820:
end
 
if 'no' == args.linklabel then
if 'none' ~= args.label then
table.insert (out, language_name); -- language name without wikilink
table.insert (out, table.concat ({args.label, ': '})); -- custom label
end
else
if 'no' == args.link then
table.insert (out, make_wikilink (language_name .. ' language', language_name)); -- language name with wikilink
table.insert (out, language_name); -- language name without wikilink
else
table.insert (out, make_wikilink (language_name .. ' language', language_name)); -- language name with wikilink
end
table.insert (out, ': '); -- separator
end
table.insert (out, ': '); -- separator
 
args.text = proto_prefix (args.text, language_name);
 
table.insert (out, make_text_span (args.code, args.text, args.rtl, args.italic, args.size))
 
-- TODO: make this transl code a separate function so that {{transl}} can use this module?
if is_set (args.translit) and not is_latn (args.text) then -- transliteration (not supported in {{lang}}); not supported when args.text is wholly latn text (this is an imperfect test)
table.insert (out, ', <small>');
if 'none' ~= args.label then
translit_script_name = lang_name_table.script[args['translit-script']] or language_name; -- if |trans-script= valid ISO 15924 code prefer associated name over language name
table.insert (out, '<small>');
translit_title = mw.title.makeTitle (0, table.concat ({'Romanization of ', translit_script_name}));
translit_script_name = lang_name_table.script[args['translit-script']] or language_name; -- if |trans-script= valid ISO 15924 code prefer associated name over language name
if translit_title.exists and ('no' ~= args.link) then
tabletranslit_title = mw.inserttitle.makeTitle (out0, make_wikilinktable.concat ({'Romanization of ' .., translit_script_name or language_name, 'translit.'})); -- make a wikilink if there is an article to link to
if translit_title.exists and ('no' ~= args.link) then
else
table.insert (out, make_wikilink ('<abbrRomanization title="transliteration">of ' .. translit_script_name or language_name, 'translit.</abbr>')); -- elsemake a wikilink if there is an article defineto thelink abbreviationto
else
table.insert (out, '<abbr title="transliteration">translit.</abbr>'); -- else define the abbreviation
end
table.insert (out, '&nbsp;</small>');
end
table.insert (out, '&nbsp;</small>');
translit = make_translit (args.code, language_name, args.translit, args['translit-std'], args['translit-script'])
if is_set (translit) then
Line 843 ⟶ 860:
if is_set (args.translation) then -- translation (not supported in {{lang}})
table.insert (out, ', <small>');
if 'nonone' =~= args.linklabel then
table.insert (out, '<abbr title="literal translation">lit.</abbrsmall>');
if 'no' == args.link then
else
table.insert (out, make_wikilink ('Literal<abbr title="literal translation', '">lit.</abbr>'));
else
table.insert (out, make_wikilink ('Literal translation', 'lit.'));
end
table.insert (out, "&nbsp;</small>");
end
table.insert (out, table.concat ({"&nbsp;</small>'", args.translation, "'"}));
table.insert (out, args.translation);
table.insert (out, "'");
end
Line 923 ⟶ 942:
return language_name;
 
end
 
 
--[[--------------------------< T R A N S L >------------------------------------------------------------------
 
Prospective replacement for the template {{transl}}
 
]]
 
function p.transl (frame)
local args = getArgs(frame); -- no {{#invoke:}} parameters
local language_name; -- language name that matches language code; used for tool tip
local translit; -- translitterated text to display
local script; -- IANA script
 
if is_set (args[1]) then
args.code = args[1]:lower(); -- IANA language code used for html lang= attribute; or ISO 15924 script code; lower case because indexes are lower case
end
 
if lang_data.override[args.code] then
language_name = lang_data.override[args.code][1];
elseif lang_name_table.lang[args.code] then
language_name = lang_name_table.lang[args.code][1];
elseif lang_name_table.script[args.code] then
language_name = lang_name_table.script[args.code][1];
script = args.code; -- code was an ISO 15924 script so use that instead
args.code = '';
else
return make_error_msg (table.concat ({'unrecognized language code: ', args})); -- invalid language code, don't know about the others (don't care?)
end
 
if is_set (args[3]) then -- [3] set when {{transl|code|standard|text}}
args.translit_std = args[2]; -- get the standard
args.translit = args[3]; -- get the transliterated text
else
if is_set (args[2]) then -- [2] set when {{transl|code|text}}
args.translit = args[2]; -- get the transliterated text
else
return make_error_msg ('no text', args);
end
end
 
translit = make_translit (args.code, language_name, args.translit, args.translit_std, script);
if not is_set (translit) then
return make_error_msg ('translit fail', args);
end
return translit;
end
 
Anonymous user