Module:Lang: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(remove deprecated entry point;)
(+|label= support;)
Line 39: Line 39:


For the purposes of this function, Latn script is characters less control characters from these Unicode 10.0 Character Code Charts:
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)
[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/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)
[http://www.unicode.org/charts/PDF/U0100.pdf Latin Extended-A] U+0100–U+017F (C4 80 - C5 BF)
Line 54: 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/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)
[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: Line 67:
{
{
'[', -- this is a set so include opening bracket
'[', -- this is a set so include opening bracket
'\32-\126', -- C0 Controls and Basic Latin U+0020–U+007E (20 - 7E)
'\n\32-\127', -- 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)
'\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)
'\195\128-\195\191', -- (skip shy) U+00C0–U+00FF (C3 80 - C3 BF)
Line 343: Line 349:
local out = {};
local out = {};
table.insert (out, table.concat ({'&#x5B;', args.text or 'undefined', '&#x5D; '})); -- for error messages output args.text if available
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%" class="error">error: ');
table.insert (out, '<span style="font-size:100%; font-style:normal;" class="error">error: ');
table.insert (out, msg);
table.insert (out, msg);
table.insert (out, ' ([[:Category:lang and lang-xx template errors|help]])')
table.insert (out, ' ([[:Category:lang and lang-xx template errors|help]])')
Line 485: Line 491:
local title_table = lang_data.translit_title_table; -- table of transliteration standards and the language codes and scripts that apply to those standards
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, "<i lang=\"");
table.insert (tout, code);
table.insert (tout, code);
table.insert (tout, "-Latn\" title=\""); -- transliterations are always Latin script
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
if not is_set (std) and not is_set (tscript) then -- when neither standard nor script specified
Line 496: Line 506:
table.insert (tout, title_table[std][tscript]); -- add the appropriate text to the tool tip
table.insert (tout, title_table[std][tscript]); -- add the appropriate text to the tool tip
else
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
end
elseif is_set (std) then -- translit-script not set, use language code
elseif is_set (std) then -- translit-script not set, use language code
if not title_table[std] then return ''; end -- invalid standard, setupt for error message
if not title_table[std] then return ''; end -- invalid standard, setup for error message
if title_table[std][code] then
if title_table[std][code] then
Line 524: Line 534:




--[[--------------------------< V A L I D A T E _ T E X T >---------------------------------------------------
--[=[-------------------------< 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
This function checks the content of args.text and returns empty string if nothing is amiss else it returns an
Line 532: Line 542:
either as ''itself''' or as '''''bold italic'''''.
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)
local function validate_text (template, args)
if not is_set (args.text) then
if not is_set (args.text) then
return make_error_msg (table.concat ({'{{', template, '}}: no text'}), args);
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
end


if 'lang-xx' == template then -- for the time being, this error checking does not apply to {{lang}}
if 'lang-xx' == template then -- for the time being, this error checking does not apply to {{lang}}
if args.text:find ("\'\'\'\'\'[\']+") then -- because we're looking, look for 6+ appostrophes
if 'unset' ~= args.italic then -- allow italic markup when |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
end
end
Line 678: Line 683:


return table.concat (out); -- put it all together and done
return table.concat (out); -- put it all together and done
end
end




Line 691: Line 696:


For normal, upright style:
For normal, upright style:
<includeonly>{{#invoke:lang|lang_xx_normal|code=xx}}</includeonly>
<includeonly>{{#invoke:lang|lang_xx_inherit|code=xx}}</includeonly>
For italic style:
For italic style:
<includeonly>{{#invoke:lang|lang_xx_italic|code=xx}}</includeonly>
<includeonly>{{#invoke:lang|lang_xx_italic|code=xx}}</includeonly>
Line 708: Line 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
|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
|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: figure out how to determine if transliteration is allowed/appropriate
for those {{lang-xx}} templates that support transliteration (those template where |text= is entirely latn script):
|translit = text that is a transliteration of text
|translit = text that is a transliteration of text
|translit-std = the standard that applies to the transliteration
|translit-std = the standard that applies to the transliteration
Line 813: Line 820:
end
end


if 'no' == args.link then
if args.label 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
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
end
table.insert (out, ': '); -- separator


args.text = proto_prefix (args.text, language_name);
args.text = proto_prefix (args.text, language_name);


table.insert (out, make_text_span (args.code, args.text, args.rtl, args.italic, args.size))
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)
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>');
table.insert (out, ', ');
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
table.insert (out, make_wikilink ('Romanization of ' .. translit_script_name or language_name, 'translit.')); -- make a wikilink if there is an article to link to
translit_title = mw.title.makeTitle (0, table.concat ({'Romanization of ', translit_script_name}));
if translit_title.exists and ('no' ~= args.link) then
else
table.insert (out, '<abbr title="transliteration">translit.</abbr>'); -- else define the abbreviation
table.insert (out, make_wikilink ('Romanization of ' .. translit_script_name or language_name, 'translit.')); -- make a wikilink if there is an article to link to
else
table.insert (out, '<abbr title="transliteration">translit.</abbr>'); -- else define the abbreviation
end
table.insert (out, '&nbsp;</small>');
end
end
table.insert (out, '&nbsp;</small>');
translit = make_translit (args.code, language_name, args.translit, args['translit-std'], args['translit-script'])
translit = make_translit (args.code, language_name, args.translit, args['translit-std'], args['translit-script'])
if is_set (translit) then
if is_set (translit) then
Line 843: Line 860:
if is_set (args.translation) then -- translation (not supported in {{lang}})
if is_set (args.translation) then -- translation (not supported in {{lang}})
table.insert (out, ', <small>');
table.insert (out, ', ');
if 'no' == args.link then
if 'none' ~= args.label then
table.insert (out, '<abbr title="literal translation">lit.</abbr>');
table.insert (out, '<small>');
if 'no' == args.link then
else
table.insert (out, make_wikilink ('Literal translation', 'lit.'));
table.insert (out, '<abbr title="literal translation">lit.</abbr>');
else
table.insert (out, make_wikilink ('Literal translation', 'lit.'));
end
table.insert (out, "&nbsp;</small>");
end
end
table.insert (out, "&nbsp;</small>'");
table.insert (out, table.concat ({"'", args.translation, "'"}));
table.insert (out, args.translation);
table.insert (out, "'");
end
end
Line 923: Line 942:
return language_name;
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
end