Modul:Lang: Perbezaan antara semakan
Kandungan dihapus Kandungan ditambah
Tiada ringkasan suntingan |
Cuba kembalikan dahulu kerana templat menjadi rosak. |
||
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 514 ⟶ 512:
if is_set (language) then
table.insert (html, table.concat ({style_added, ' title=\"'})); -- start of the title text
if language:find ('
table.insert (html, table.concat ({' Teks kolektif
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:
[[
for English:
[[
for artificial languages (code: art)
[[
for ISO 639-2 collective languages (and for 639-1 bh):
[[
]=]
Baris 559 ⟶ 557:
end
if language_name:find ('
return table.concat ({'[[
end
table.insert (cat, '[[
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,
if not language_name:find ('
table.insert (tout, 'bahasa ') -- skip this text (individual and macro languages only)
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
if title_table[std][tscript] then -- and if script for that standard is legitimate
table.insert (tout, table.concat ({
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 ({
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, '
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, '-language') -- skip this text (individual and macro languages only)
end
table.insert (tout, ' transliteration'); -- finish the tool tip
else
table.insert (tout, '
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 ({'[[
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
]]
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 ⟶ 791:
end
--[[--------------------------< L A N G >----------------------------------------------------------------------
Baris 827 ⟶ 803:
]]
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 834 ⟶ 824:
local msg; -- for error messages
local tag = 'span'; -- initial value for make_text_html()
if args[1] and args.code then
Baris 848 ⟶ 837:
end
msg = validate_text (
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
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
(
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
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 _ X X >----------------------------------------------------------------
Baris 986 ⟶ 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 998 ⟶ 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,014 ⟶ 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,020 ⟶ 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,028 ⟶ 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,040 ⟶ 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,066 ⟶ 1,041:
args.rtl = false; -- script is not an rtl script
end
end
Baris 1,103 ⟶ 1,074:
table.insert (out, language_name); -- language name without wikilink
else
if language_name:find ('
table.insert (out, make_wikilink (language_name)); -- collective language name uses simple wikilink
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
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,
end
end
Baris 1,166 ⟶ 1,135:
return table.concat (out); -- put it all together and done
end
Baris 1,204 ⟶ 1,145:
local function lang_xx_italic (frame)
initial_style_state = 'italic';
return _lang_xx (
end
Baris 1,230 ⟶ 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,288 ⟶ 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,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 ('
return make_wikilink (language_name); -- collective language name uses simple wikilink
else
return make_wikilink ('Bahasa ' .. language_name, 'Bahasa ' .. language_name); -- language name with wikilink
Baris 1,338 ⟶ 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,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
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
transl = transl, -- entry point for {{transl}}
};
|