Modul:Lang: Perbezaan antara semakan

Kandungan dihapus Kandungan ditambah
Tiada ringkasan suntingan
Polar (bincang | sumb.)
Cuba kembalikan dahulu kerana templat menjadi rosak.
Baris 20:
 
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
 
local this_wiki_lang = mw.language.getContentLanguage().code; -- get this wiki's language
 
local maint_cats = {}; -- maintenance categories go here
Baris 77 ⟶ 75:
end
 
seg[1] = invert_pattern_table[seg[1]]:gsub or(".*", invert_pattern_table, seg[1]); -- replace leading markup according to pattern table
seg[3] = invert_pattern_table[seg[3]]:gsub or(".*", seg[3]invert_pattern_table, 1); -- replace leading markup according to pattern table
 
return table.concat (seg); -- put it all back together and done
Baris 514 ⟶ 512:
 
if is_set (language) then
table.insert (html, table.concat ({style_added, ' title=\"'})); -- start of the title text
if language:find ('[Bb]ahasaBahasa-bahasa' or '[Bb]ahasa') then
table.insert (html, table.concat ({' Teks kolektif bahasa ', language, '\"'})); -- for collective languages
else
table.insert (html, table.concat ({' Teks bahasa ', language, '\"'})); -- for individual languages
end
table.insert (html, '>'); -- close the opening html tag
Baris 539 ⟶ 537:
 
For individual language, <language>, returns:
[[KategoriCategory:Articles containing <language>-language text]]
 
for English:
[[KategoriCategory:Articles containing explicitly cited English-language text]]
for artificial languages (code: art)
[[KategoriCategory:Articles containing constructed-language text]]
 
for ISO 639-2 collective languages (and for 639-1 bh):
[[KategoriCategory:Articles with text from the <language> languages collective]]
 
]=]
Baris 559 ⟶ 557:
end
if language_name:find ('[Bb]ahasaBahasa-bahasa' or '[Bb]ahasa') then
return table.concat ({'[[KategoriCategory:Rencana dengan teks kolektif dari bahasa ', language_name, ']]'});
end
table.insert (cat, '[[KategoriCategory:Rencana yang mengandungi teks bahasa ');
if 'ms' == code then
Baris 615 ⟶ 613:
if not is_set (std) and not is_set (tscript) then -- when neither standard nor script specified
table.insert (tout, language_name'Transliterasi '); -- write afinish genericthe tool tip
if not language_name:find ('[Bb]ahasaBahasa-bahasa' or '[Bb]ahasa') then -- collective language names (plural 'languages' is part of the name)
table.insert (tout, 'bahasa ') -- skip this text (individual and macro languages only)
end
table.insert (tout, 'Transliterasi 'language_name); -- finishwrite a thegeneric tool tip
elseif is_set (std) and is_set (tscript) then -- when both are specified
if title_table[std] then -- and if standard is legitimate
if title_table[std][tscript] then -- and if script for that standard is legitimate
table.insert (tout, table.concat ({'Transliterasi ', title_table[std][tscript:lower()], ' (tulisan bahasa ', lang_name_table.script[tscript][1], ' script) transliteration'})); -- 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; TODO: maint cat? error message because script not found for this standard?
Baris 635 ⟶ 633:
if title_table[std][code] then -- if language code is in the table (transl may not provide a language code)
table.insert (tout, table.concat ({'Transliterasi ', title_table[std][code:lower()], ' (bahasa ', lang_name_table.lang[code][1], ' language) transliteration'})); -- add the appropriate text to the tool tip
else -- code doesn't match
table.insert (tout, title_table[std]['default']); -- so use the standard's default
Baris 646 ⟶ 644:
else
if is_set (tscript) then
table.insert (tout, table.concat ({language_name, 'Transliterasi tulisan bahasa-script transliteration', language_name})); -- write a script tool tip
elseif is_set (code) then
if not language_name:find ('Bahasa-bahasa') then -- collective language names (plural 'languages' is part of the name)
table.insert (tout, 'transliterasi '); -- finish the tool tip
table.insert (tout, '-language') -- skip this text (individual and macro languages only)
if not language_name:find ('[Bb]ahasa-bahasa' or '[Bb]ahasa') then -- collective language names (plural 'languages' is part of the name)
table.insert (tout, 'bahasa ') -- skip this text (individual and macro languages only)
end
table.insert (tout, ' transliteration'); -- finish the tool tip
else
table.insert (tout, 'transliterasi transliteration'); -- generic tool tip (can we ever get here?)
end
end
Baris 717 ⟶ 715:
if (0 < #maint_cats) and (0 == namespace) and not nocat then -- when there are maintenance categories; article namespace only
for _, cat in ipairs (maint_cats) do
table.insert (maint, table.concat ({'[[KategoriCategory:', cat, ']]'})); -- format and add the categories
end
end
Baris 730 ⟶ 728:
will be rendered outside of italic markup (if used). If the first character in text here is already a splat, we
do nothing
 
proto_param is boolean or nil; true adds splat prefix regardless of language name; false removes and / or inhibits
regardless of language name; nil does nothing; presumes that the value in text is correct but removes extra splac
 
]]
 
local function proto_prefix (text, language_name, proto_param)
if language_name:find ('^Proto%-') and not text:find ('^*') then -- language is a proto and text does not already have leading splat
if false == proto_param then -- when forced by |proto=no
return text:gsubtable.concat ({'^%**', ''text}); -- return text without splat prefix regardless ofproto language nametext orwith existinga splat prefix in text
elseif (language_name:find ('^Proto%-') or (true == proto_param)) then -- language is a proto or forced by |proto=yes
return text:gsub ('^%**', '*'); -- prefix proto-language text with a splat; also removes duplicate prefixing splats
end
return text;
return text:gsub ('^%*+', '*'); -- return text unmolested except multiple splats reduced to one splat
end
 
Baris 798 ⟶ 791:
end
 
--[[--------------------------< V A L I D A T E _ P R O T O >--------------------------------------------------
validates value assigned to |proto=; permitted values are yes and no; yes returns as true, no returns as false,
empty string (or parameter omitted) returns as nil; any other value returns as nil with a second return value of
true indicating that some other value has been assigned to |proto=
]]
 
local function validate_proto (proto_param)
if 'yes' or 'ya' == proto_param then
return true;
elseif 'no' or 'tidak' == proto_param then
return false;
elseif is_set (proto_param) then
return nil, true; -- |proto= something other than 'yes' or 'no'
else
return nil; -- missing or empty
end
end
 
--[[--------------------------< L A N G >----------------------------------------------------------------------
Baris 827 ⟶ 803:
]]
 
local function _langlang (argsframe)
local args = getArgs (frame, { -- this code so that we can detect and handle wiki list markup in text
valueFunc = function (key, value)
if 2 == key or 'text' == key then -- the 'text' parameter; do not trim wite space
return value; -- return untrimmed 'text'
elseif value then -- all other values: if the value is not nil
value = mw.text.trim (value); -- trim whitespace
if '' ~= value then -- empty string when value was only whitespace
return value;
end
end
return nil; -- value was empty or contained only whitespace
end -- end of valueFunc
});
 
local out = {};
local language_name; -- used to make category names
Baris 834 ⟶ 824:
local msg; -- for error messages
local tag = 'span'; -- initial value for make_text_html()
local template = args.template or 'lang';
 
if args[1] and args.code then
Baris 848 ⟶ 837:
end
msg = validate_text (template'lang', args); -- ensure that |text= is set
if is_set (msg) then -- msg is an already-formatted error message
return msg;
Baris 858 ⟶ 847:
 
args.rtl = args.rtl == 'yes'; -- convert to boolean: 'yes' -> true, other values -> false
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag
if msg then
return make_error_msg (table.concat ({'&#124;proto=: ', args.proto, ' tidak sah'}), args, template);
end
 
code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (args.code); -- |script=, |region=, |variant= not supported because they should be part of args.code ({{{1}}} in {{lang}})
Baris 877 ⟶ 861:
if nil == args.italic then -- nil when |italic= absent or not set or |italic=default; args.italic controls
if ('latn' == subtags.script) or -- script is latn
(this_wiki_lang'en' ~= code and not is_set (subtags.script) and not has_poem_tag (args.text) and unicode.is_Latin (args.text)) then -- text not this wiki's languageEnglish, no script specified and not in poem markup but is wholly latn script (auto-italics)
args.italic = 'italic'; -- DEFAULT for {{lang}} templates is upright; but if latn script set for font-style:italic
else
Baris 908 ⟶ 892:
end
args.text = proto_prefix (args.text, language_name, args.proto); -- prefix proto-language text with a splat
 
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.italic, args.size, language_name));
Baris 917 ⟶ 901:
end
 
--[[--------------------------< L A N G >----------------------------------------------------------------------
entry point for {{lang}}
there should be no reason to set parameters in the {{lang}} {{#invoke:}}
<includeonly>{{#invoke:lang|lang}}</includeonly>
parameters are received from the template's frame (parent frame)
]]
 
local function lang (frame)
local args = getArgs (frame, { -- this code so that we can detect and handle wiki list markup in text
valueFunc = function (key, value)
if 2 == key or 'text' == key then -- the 'text' parameter; do not trim wite space
return value; -- return untrimmed 'text'
elseif value then -- all other values: if the value is not nil
value = mw.text.trim (value); -- trim whitespace
if '' ~= value then -- empty string when value was only whitespace
return value;
end
end
return nil; -- value was empty or contained only whitespace
end -- end of valueFunc
});
return _lang (args);
 
end
 
--[[--------------------------< L A N G _ X X >----------------------------------------------------------------
Baris 986 ⟶ 946:
]]
 
local function _lang_xx (argsframe)
local args = getArgs(frame,
{
parentFirst= true, -- parameters in the template override parameters set in the {{#invoke:}}
valueFunc = function (key, value)
if 1 == key then -- the 'text' parameter; do not trim wite space
return value; -- return untrimmed 'text'
elseif value then -- all other values: if the value is not nil
value = mw.text.trim (value); -- trim whitespace
if '' ~= value then -- empty string when value was only whitespace
return value;
end
end
return nil; -- value was empty or contained only whitespace
end -- end of valueFunc
});
 
local out = {};
local language_name; -- used to make display text, article links
Baris 998 ⟶ 974:
local msg; -- for error messages
local tag = 'span'; -- initial value for make_text_html()
local template = args.template or 'lang-xx';
 
if args[1] and args.text then
return make_error_msg ('conflicting: {{{1}}} and &#124;text=', args, template'lang-xx');
else
args.text = args[1] or args.text; -- prefer args.text
end
msg = validate_text (template'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;
Baris 1,014 ⟶ 989:
 
if args[2] and args.translit then
return make_error_msg ('conflicting: {{{2}}} and &#124;translit=', args, template'lang-xx');
else
args.translit = args[2] or args.translit -- prefer args.translit
Baris 1,020 ⟶ 995:
if args[3] and (args.translation or args.lit) then
return make_error_msg ('conflicting: {{{3}}} and &#124;lit= or &#124;translation=', args, template'lang-xx');
elseif args.translation and args.lit then
return make_error_msg ('conflicting: &#124;lit= and &#124;translation=', args, template'lang-xx');
else
args.translation = args[3] or args.translation or args.lit; -- prefer args.translation
Baris 1,028 ⟶ 1,003:
 
if args.links and args.link then
return make_error_msg ('conflicting: &#124;links= and &#124;link=', args, template'lang-xx');
else
args.link = args.link or args.links; -- prefer args.link
Baris 1,040 ⟶ 1,015:
 
if msg then -- if an error detected then there is an error message
return make_error_msg (msg, args, template'lang-xx');
end
args.italic, msg = validate_italic (args);
if msg then
return make_error_msg (msg, args, template'lang-xx');
end
 
Baris 1,066 ⟶ 1,041:
args.rtl = false; -- script is not an rtl script
end
end
args.proto, msg = validate_proto (args.proto); -- return boolean, or nil, or nil and error message flag
if msg then
return make_error_msg (table.concat ({'invalid &#124;proto=: ', args.proto}), args, template);
end
 
Baris 1,103 ⟶ 1,074:
table.insert (out, language_name); -- language name without wikilink
else
if language_name:find ('[Bb]ahasaBahasa-bahasa' or '[Bb]ahasa') then
table.insert (out, make_wikilink (language_name)); -- collective language name uses simple wikilink
elseif lang_data.article_name[code] then
table.insert (out, make_wikilink (lang_data.article_name[code][1], language_name)); -- language name with wikilink from override data
else
table.insert (out, make_wikilink ('Bahasa ' .. language_name, 'Bahasa ' .. language_name)); -- language name with wikilink
Baris 1,118 ⟶ 1,087:
end
args.text = proto_prefix (args.text, language_name, args.proto); -- prefix proto-language text with a splat
 
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.italic, args.size))
Baris 1,144 ⟶ 1,113:
table.insert (out, translit);
else
return make_error_msg (table.concat ({'invalid translit-std: \'', args['translit-std'] or '[missing]'}), args, template'lang-xx');
end
end
Baris 1,166 ⟶ 1,135:
 
return table.concat (out); -- put it all together and done
end
 
--[[--------------------------< L A N G _ X X _ A R G S _ G E T >----------------------------------------------
 
common function to get args table from {{lang-??}} templates
 
returns table of args
 
]]
 
local function lang_xx_args_get (frame)
local args = getArgs(frame,
{
parentFirst= true, -- parameters in the template override parameters set in the {{#invoke:}}
valueFunc = function (key, value)
if 1 == key then -- the 'text' parameter; do not trim wite space
return value; -- return untrimmed 'text'
elseif value then -- all other values: if the value is not nil
value = mw.text.trim (value); -- trim whitespace
if '' ~= value then -- empty string when value was only whitespace
return value;
end
end
return nil; -- value was empty or contained only whitespace
end -- end of valueFunc
});
 
return args;
end
 
Baris 1,204 ⟶ 1,145:
 
local function lang_xx_italic (frame)
local args = lang_xx_args_get (frame);
initial_style_state = 'italic';
return _lang_xx (argsframe);
end
 
 
--[[--------------------------< _ L A N G _ X X _ I T A L I C >------------------------------------------------
 
Entry point ffrom another module. Sets the initial style state to italic.
 
]]
 
local function _lang_xx_italic (args)
initial_style_state = 'italic';
return _lang_xx (args);
end
 
Baris 1,230 ⟶ 1,157:
 
local function lang_xx_inherit (frame)
local args = lang_xx_args_get (frame);
 
initial_style_state = 'inherit';
return _lang_xx (args);
end
 
 
--[[--------------------------< _ L A N G _ X X _ I N H E R I T >----------------------------------------------
 
Entry point from another module. Sets the initial style state to inherit.
 
]]
 
local function _lang_xx_inherit (args)
initial_style_state = 'inherit';
return _lang_xx (argsframe);
end
 
 
--[[--------------------------< _ I S _ I E T F _ TC AO GD E >------------------------------------------------------
 
Returns true when a language name associated with IETF language tag exists; nil else. IETF language tag must be valid.
 
All code combinations supported by {{lang}} and the {{lang-xx}} templates are supported by this function.
 
The purpose of this function is to replace {{#ifexist:Template:ISO 639 name xx|<exists>|<does not exist>}} in
templates that are better served by using {{#invoke:lang|name_from_tagname_from_code|<code>}}
 
Module entry point from another module
 
]]
 
local function is_ietf_code (frame)
local function _is_ietf_tag (tag) -- entry point when this module is require()d into another
return get_ietf_parts (frame.args[1]) and true;
local c, s, r, v, p, err; -- code, script, region, private, error message
c, s, r, v, p, err = get_ietf_parts (tag); -- disassemble tag into constituent part and validate
return ((c and not err) and true) or nil; -- return true when code portion has a value without error message; nil else
end
 
 
--[[--------------------------< IN SA _ IM E T_ F R O M _ TC AO GD E >--------------------------------------------------------
 
Module entry point from an {{#invoke:}}
 
]]
 
local function is_ietf_tag (frame) -- entry point from an {{#invoke:Lang|is_ietf_tag|<ietf tag>}}
return _is_ietf_tag (frame.args[1]); -- frame.args[1] is the ietf language tag
end
 
 
--[[--------------------------< _ N A M E _ F R O M _ C O D E >------------------------------------------------
 
Returns language name associated with IETF language tag if valid; empty string else.
Baris 1,288 ⟶ 1,185:
 
Set invoke's |link= parameter to yes to get wikilinked version of the language name.
 
Module entry point from another module
 
]]
 
local function _name_from_tagname_from_code (argsframe)
local subtags = {}; -- IETF subtags script, region, variant, and private
local raw_code = frame.args[1]; -- save a copy of the input IETF subtag
local link = 'yes' == frame.args['link']; -- makesave a booleancopy of the link-enable positional parameter (value can be anything)
local code; -- the language code
local msg; -- gets an error message if IETF language tag is malformed or invalid
Baris 1,303 ⟶ 1,198:
code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (raw_code);
if msg then
local template = (frame.args['template'] and table.concat ({'{{', frame.args['template'], '}}: '})) or ''; -- make template name (if provided by the template)
return table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: ', template, msg, '</span>'});
end
Baris 1,324 ⟶ 1,219:
 
if link then -- when |link=yes, wikilink the language name
if language_name:find ('[Bb]ahasaBahasa-bahasa' or '[Bb]ahasa') then
return make_wikilink (language_name); -- collective language name uses simple wikilink
elseif lang_data.article_name[code] then
return make_wikilink (lang_data.article_name[code][1], language_name); -- language name with wikilink from override data
else
return make_wikilink ('Bahasa ' .. language_name, 'Bahasa ' .. language_name); -- language name with wikilink
Baris 1,338 ⟶ 1,231:
 
 
--[[--------------------------< N A M E _ FT R OA M _ C ON DS EL >------------------------------------------------------------------
 
Module entryEntry point from anfor {{#invoke:transl}}
 
]]
 
local function transl (frame)
local function name_from_tag (frame) -- entry point from an {{#invoke:Lang|name_from_tag|<ietf tag>|link=<yes>|template=<template name>}}
returnlocal _name_from_tagargs = getArgs(frame.args); -- pass-on the args table,no nothing{{#invoke:}} elseparameters
end
 
 
--[[--------------------------< _ T A G _ F R O M _ N A M E >--------------------------------------------------
 
Returns the ietf language tag associated with the language name. Spelling of language name must be correct
according to the spelling in the source tables. When a standard language name has a parenthetical disambiguator,
that disambiguator must be omitted (they are not present in the data name-to-tag tables).
 
Module entry point from another module
 
]]
 
local function _tag_from_name (args) -- entry point from another module
local msg;
 
if args[1] and '' ~= args[1] then
local data = mw.loadData ('Module:Lang/name to tag'); -- get the reversed data tables
local lang = args[1]:lower(); -- allow any-case for the language name (speeling must till be correct)
local tag = data.rev_lang_data[lang] or data.rev_lang_name_table[lang];-- get the code; look first in the override then in the standard
 
if tag then
return tag; -- language name found so return tag and done
else
msg = 'language: ' .. args[1] .. ' not found' -- language name not found, error message
end
else
msg = 'missing language name' -- language name not provided, error message
end
 
local template = '';
if args.template and '' ~= args.template then
template = table.concat ({'{{', args['template'], '}}: '}); -- make template name (if provided by the template)
end
return table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: ', template, msg, '</span>'});
end
 
 
--[[--------------------------< T A G _ F R O M _ N A M E >----------------------------------------------------
 
Module entry point from an {{#invoke:}}
 
]]
 
local function tag_from_name (frame) -- entry point from an {{#invoke:Lang|tag_from_name|<language name>|link=<yes>|template=<template name>}}
return _tag_from_name (frame.args); -- pass-on the args table, nothing else
end
 
 
--[[--------------------------< _ T R A N S L >----------------------------------------------------------------
 
Module entry point from another module
 
]]
 
local function _transl (args)
local title_table = lang_data.translit_title_table; -- table of transliteration standards and the language codes and scripts that apply to those standards
local language_name; -- language name that matches language code; used for tool tip
Baris 1,460 ⟶ 1,297:
-- here only when all parameters passed to make_translit() are valid
return make_translit (args.code, language_name, args.text, args.translit_std, script, args.italic);
end
 
 
--[[--------------------------< T R A N S L >------------------------------------------------------------------
 
Module entry point from an {{#invoke:}}
 
]]
 
local function transl (frame)
local args = getArgs(frame); -- no {{#invoke:}} parameters
return _transl (args);
end
 
Baris 1,480 ⟶ 1,305:
return {
lang = lang, -- entry point for {{lang}}
is_ietf_code = is_ietf_code,
lang_xx_inherit = lang_xx_inherit, -- entry points for {{lang-??}}
lang_xx_italic = lang_xx_italic,
name_from_code = name_from_code, -- used for template documentation; possible use in ISO 639 name from code templates
is_ietf_tag = is_ietf_tag,
tag_from_name = tag_from_name, -- returns ietf tag associated with language name
name_from_tag = name_from_tag, -- used for template documentation; possible use in ISO 639 name from code templates
transl = transl, -- entry point for {{transl}}
 
_lang = _lang, -- entry points when this module is require()d into other modules
_lang_xx_inherit = _lang_xx_inherit,
_lang_xx_italic = _lang_xx_italic,
_is_ietf_tag = _is_ietf_tag,
_tag_from_name = _tag_from_name,
_name_from_tag = _name_from_tag,
_transl = _transl,
};