Modul:Lang: Perbezaan antara semakan
Kandungan dihapus Kandungan ditambah
kTiada ringkasan suntingan |
Reverted to revision 4516191 by Zulfadli51 (talk): Templat jadi rosak. (TW) Teg: Buat asal |
||
Baris 20:
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local maint_cats = {}; -- maintenance categories go here
Baris 77 ⟶ 75:
end
seg[1] =
seg[3] =
return table.concat (seg); -- put it all back together and done
Baris 114 ⟶ 112:
local count = 0
for _, arg in pairs {'italic', 'italics', 'i', 'italik'} do
if args[arg] then
count = count + 1
Baris 121 ⟶ 119:
if count > 1 then -- return nil and an error message if more than one is set
return nil, '
end
Baris 246 ⟶ 244:
if not is_set (source) then
return nil, nil, nil, nil, nil, '
end
Baris 301 ⟶ 299:
if not code then
return nil, nil, nil, nil, nil, table.concat ({'
end
Baris 307 ⟶ 305:
if not (lang_data.override[code] or lang_name_table.lang[code]) then
return nil, nil, nil, nil, nil, table.concat ({'
end
if synonym_table[code] then -- if 639-2/639-2T code has a 639-1 synonym
table.insert (maint_cats, table.concat ({'
table.insert (maint_msgs, table.concat ({'
code = synonym_table[code]; -- use the synonym
end
Baris 318 ⟶ 316:
if is_set (script) then
if is_set (args_script) then
return code, nil, nil, nil, nil, '
end
else
Baris 327 ⟶ 325:
script = script:lower(); -- ensure that we use and return lower case version of this
if not lang_name_table.script[script] then
return code, nil, nil, nil, nil, table.concat ({'
end
end
if lang_name_table.suppressed[script] then -- ensure that code-script does not use a suppressed script
if in_array (code, lang_name_table.suppressed[script]) then
return code, nil, nil, nil, nil, table.concat ({'
end
end
Baris 338 ⟶ 336:
if is_set (region) then
if is_set (args_region) then
return code, nil, nil, nil, nil, '
end
else
Baris 347 ⟶ 345:
region = region:lower(); -- ensure that we use and return lower case version of this
if not lang_name_table.region[region] then
return code, script, nil, nil, nil, table.concat ({'
end
end
Baris 353 ⟶ 351:
if is_set (variant) then
if is_set (args_variant) then
return code, nil, nil, nil, nil, '
end
else
Baris 362 ⟶ 360:
variant = variant:lower(); -- ensure that we use and return lower case version of this
if not lang_name_table.variant[variant] then -- make sure variant is valid
return code, script, region, nil, nil, table.concat ({'
end -- does this duplicate/replace tests in lang() and lang_xx()?
if is_set (script) then -- if script set it must be part of the 'prefix'
if not in_array (table.concat ({code, '-', script}), lang_name_table.variant[variant]['prefixes']) then
return code, script, region, nil, nil, table.concat ({'
end
else
if not in_array (code, lang_name_table.variant[variant]['
return code, script, region, nil, nil, table.concat ({'
end
end
Baris 378 ⟶ 376:
private = private:lower(); -- ensure that we use and return lower case version of this
if not lang_data.override[table.concat ({code, '-x-', private})] then -- make sure private tag is valid; note that index
return code, script, region, nil, nil, table.concat ({'
end
end
Baris 398 ⟶ 396:
category = 'transl';
else
category = 'lang
end
Baris 404 ⟶ 402:
table.insert (out, table.concat ({'<span style=\"font-size:100%; font-style:normal;\" class=\"error\">error: {{', template, '}}: '}));
table.insert (out, msg);
table.insert (out, table.concat ({' ([[:
table.insert (out, '</span>');
if (0 == namespace) and not args.nocat then -- only categorize in article space
table.insert (out, table.concat ({'[[
end
Baris 480 ⟶ 478:
if text:match ('^%*') then
table.insert (html, '*'); -- move proto language text prefix outside of italic markup if any; use numeric entity because
text = text:gsub ('^%*', ''); -- remove the splat from the text
end
Baris 514 ⟶ 512:
if is_set (language) then
table.insert (html, table.concat ({style_added, ' title=\"'
if language:find ('
table.insert (html, table.concat ({'
else
table.insert (html, table.concat ({' Teks bahasa ', language,
end
table.insert (html, '>'); -- close the opening html tag
Baris 559 ⟶ 557:
end
if language_name:find ('
return table.concat ({'[[Category:
end
table.insert (cat, '[[Category:
if '
table.insert (cat, '
elseif 'art' == code then
table.insert (cat, '
else
table.insert (cat, language_name .. ']]');
end
return table.concat (cat);
Baris 603 ⟶ 599:
if is_set (code) then -- when a language code is provided (always with {{lang-xx}} templates, not always with {{transl}})
if not style then -- nil for is the default italic style
table.insert (tout, "<i lang=\""); -- so use <i> tag
else
Baris 617 ⟶ 613:
if not is_set (std) and not is_set (tscript) then -- when neither standard nor script specified
table.insert (tout,
if not language_name:find ('
table.insert (tout, '
end
table.insert (tout,
elseif is_set (std) and is_set (tscript) then -- when both are specified
if title_table[std] then -- and if standard is legitimate
Baris 650 ⟶ 646:
table.insert (tout, table.concat ({language_name, '-script transliteration'})); -- write a script tool tip
elseif is_set (code) then
if not language_name:find ('
table.insert (tout, '-language') -- skip this text (individual and macro languages only)
end
Baris 662 ⟶ 658:
table.insert (tout, '">');
table.insert (tout, translit);
if is_set (code) and not style then -- when a language code is provided (always with {{lang-xx}} templates, not always with {{transl}})
table.insert (tout, "</i>"); -- close the italic tag
else
Baris 683 ⟶ 679:
local function validate_text (template, args)
if not is_set (args.text) then
return make_error_msg ('
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 ('
end
Baris 694 ⟶ 690:
if ('unset' ~= style) and ('invert' ~=style) then
if args.text:find ("%f[\']\'\'%f[^\']") or args.text:find ("%f[\']\'\'\'\'\'%f[^\']") then -- italic but not bold, or bold italic
return make_error_msg ('
end
end
Baris 732 ⟶ 728:
will be rendered outside of italic markup (if used). If the first character in text here is already a splat, we
do nothing
]]
local function proto_prefix (text, language_name
if language_name:find ('^Proto%-') and not text:find ('^*') then -- language is a proto and text does not already have leading splat
return
end
return text;
end
Baris 798 ⟶ 789:
return text, tag;
end
Baris 829 ⟶ 799:
<includeonly>{{#invoke:lang|lang}}</includeonly>
parameters are
]]
local function
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 840 ⟶ 824:
local msg; -- for error messages
local tag = 'span'; -- initial value for make_text_html()
if args[1] and args.code then
Baris 854 ⟶ 837:
end
msg = validate_text (
if is_set (msg) then -- msg is an already-formatted error message
return msg;
Baris 864 ⟶ 847:
args.rtl = args.rtl == 'yes'; -- convert to boolean: 'yes' -> true, other values -> false
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 883 ⟶ 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
(
args.italic = 'italic'; -- DEFAULT for {{lang}} templates is upright; but if latn script set for font-style:italic
else
Baris 913 ⟶ 891:
args.text = invert_italics (args.text)
end
args.text = proto_prefix (args.text, language_name
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.italic, args.size, language_name));
Baris 921 ⟶ 899:
return table.concat (out); -- put it all together and done
end
Baris 998 ⟶ 946:
]]
local function _lang_xx (
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 1,010 ⟶ 974:
local msg; -- for error messages
local tag = 'span'; -- initial value for make_text_html()
if args[1] and args.text then
return make_error_msg ('conflicting: {{{1}}} and |text=', args,
else
args.text = args[1] or args.text; -- prefer args.text
end
msg = validate_text (
if is_set (msg) then
return msg;
Baris 1,026 ⟶ 989:
if args[2] and args.translit then
return make_error_msg ('conflicting: {{{2}}} and |translit=', args,
else
args.translit = args[2] or args.translit -- prefer args.translit
Baris 1,032 ⟶ 995:
if args[3] and (args.translation or args.lit) then
return make_error_msg ('conflicting: {{{3}}} and |lit= or |translation=', args,
elseif args.translation and args.lit then
return make_error_msg ('conflicting: |lit= and |translation=', args,
else
args.translation = args[3] or args.translation or args.lit; -- prefer args.translation
Baris 1,040 ⟶ 1,003:
if args.links and args.link then
return make_error_msg ('conflicting: |links= and |link=', args,
else
args.link = args.link or args.links; -- prefer args.link
Baris 1,052 ⟶ 1,015:
if msg then -- if an error detected then there is an error message
return make_error_msg (msg, args,
end
args.italic, msg = validate_italic (args);
if msg then
return make_error_msg (msg, args,
end
Baris 1,078 ⟶ 1,041:
args.rtl = false; -- script is not an rtl script
end
end
Baris 1,116 ⟶ 1,074:
table.insert (out, language_name); -- language name without wikilink
else
if language_name:find ('Bahasa-bahasa') then
table.insert (out, make_wikilink (language_name)); -- collective language name uses simple wikilink
else
table.insert (out, make_wikilink ('
end
end
Baris 1,131 ⟶ 1,087:
end
args.text = proto_prefix (args.text, language_name
table.insert (out, make_text_html (args.code, args.text, tag, args.rtl, args.italic, args.size))
Baris 1,144 ⟶ 1,100:
translit_script_name = language_name; -- fall back on language name
end
translit_title = mw.title.makeTitle (0, table.concat ({'
if translit_title.exists and ('no' ~= args.link) then
table.insert (out, make_wikilink ('
else
table.insert (out, '
end
table.insert (out, ' </small>'); -- close the small tag
Baris 1,157 ⟶ 1,113:
table.insert (out, translit);
else
return make_error_msg (table.concat ({'invalid translit-std: \'', args['translit-std'] or '[missing]'}), args,
end
end
Baris 1,166 ⟶ 1,122:
table.insert (out, '<small>');
if 'no' == args.link then
table.insert (out, '<abbr title="
else
table.insert (out, make_wikilink ('
end
table.insert (out, " </small>");
Baris 1,179 ⟶ 1,135:
return table.concat (out); -- put it all together and done
end
Baris 1,218 ⟶ 1,145:
local function lang_xx_italic (frame)
initial_style_state = 'italic';
return _lang_xx (
end
Baris 1,244 ⟶ 1,157:
local function lang_xx_inherit (frame)
initial_style_state = 'inherit';
return _lang_xx (
end
--[[--------------------------<
Returns true when a language name associated with IETF language tag exists; nil else
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|
]]
local function is_ietf_code (frame)
return get_ietf_parts (frame.args[1]) and true;
end
--[[--------------------------<
Returns language name associated with IETF language tag if valid; empty string else.
Baris 1,302 ⟶ 1,185:
Set invoke's |link= parameter to yes to get wikilinked version of the language name.
]]
local function
local subtags = {}; -- IETF subtags script, region, variant, and private
local raw_code = frame.args[1];
local link = 'yes' == frame.args['link'];
local code; -- the language code
local msg; -- gets an error message if IETF language tag is malformed or invalid
Baris 1,317 ⟶ 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,338 ⟶ 1,219:
if link then -- when |link=yes, wikilink the language name
if language_name:find ('Bahasa-bahasa') then
return make_wikilink (language_name); -- collective language name uses simple wikilink
else
return make_wikilink ('
end
end
Baris 1,352 ⟶ 1,231:
--[[--------------------------<
]]
local function transl (frame)
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,474 ⟶ 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
Baris 1,494 ⟶ 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
transl = transl, -- entry point for {{transl}}
};
|