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 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 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, 'onlyhanya onesatu ofdari |italic=, |italics=, or |i= canatau |italik= beboleh specifieddiperincikan';
end
Baris 246 ⟶ 244:
 
if not is_set (source) then
return nil, nil, nil, nil, nil, 'missingteg languagebahasa taghilang';
end
 
Baris 301 ⟶ 299:
 
if not code then
return nil, nil, nil, nil, nil, table.concat ({'unrecognizedteg languagebahasa tagtidak diiktiraf: ', source}); -- don't know what we got but it is malformed
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 ({'unrecognizedteg languagebahasa codetidak diiktiraf: ', code}); -- invalid language code, don't know about the others (don't care?)
end
if synonym_table[code] then -- if 639-2/639-2T code has a 639-1 synonym
table.insert (maint_cats, table.concat ({'LangKod andlang dan lang-xx code promoteddigalakkan toke ISO 639-1|', code}));
table.insert (maint_msgs, table.concat ({'codekod: ', code, ' promoteddigalakkan toke codekod: ', synonym_table[code]}));
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, 'redundantteg scriptaksara taglewah'; -- both code with script and |script= not allowed
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 ({'unrecognizedaksara scripttidak diiktiraf: ', script, ' foruntuk codekod: ', code}); -- language code ok, invalid script, don't know about the others (don't care?)
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 ({'scriptaksara: ', script, ' nottidak supporteddisokong foruntuk codekod: ', code}); -- language code ok, script is suppressed for this code
end
end
Baris 338 ⟶ 336:
if is_set (region) then
if is_set (args_region) then
return code, nil, nil, nil, nil, 'redundantteg regionrantau taglewah'; -- both code with region and |region= not allowed
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 ({'unrecognizedrantau regiontidak diiktiraf: ', region, ' foruntuk codekod: ', code});
end
end
Baris 353 ⟶ 351:
if is_set (variant) then
if is_set (args_variant) then
return code, nil, nil, nil, nil, 'redundantteg variantvarian taglewah'; -- both code with variant and |variant= not allowed
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 ({'unrecognizedvarian varianttidak diiktiraf: ', variant});
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 ({'unrecognizedvarian varianttidak diiktiraf: ', variant, ' foruntuk pasangan code-scriptaksara pairkod: ', code, '-', script});
end
else
if not in_array (code, lang_name_table.variant[variant]['prefixesawalan']) then
return code, script, region, nil, nil, table.concat ({'unrecognizedvarian varianttidak diiktiraf: ', variant, ' foruntuk codekod: ', code});
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 ({'unrecognizedteg privatepersendirian tagtidak diiktiraf: ', private});
end
end
Baris 398 ⟶ 396:
category = 'transl';
else
category = 'lang anddan lang-xx'
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 ({' ([[:CategoryKategori:Ralat templat ', category, ' template errors|helpbantuan]])'}));
table.insert (out, '</span>');
if (0 == namespace) and not args.nocat then -- only categorize in article space
table.insert (out, table.concat ({'[[CategoryKategori:Ralat templat ', category, ' template errors]]'}));
end
 
Baris 480 ⟶ 478:
 
if text:match ('^%*') then
table.insert (html, '&#42;'); -- move proto language text prefix outside of italic markup if any; use numeric entity because plainplane splat confuses MediaWiki
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=\"', language})); -- start of the title text
if language:find ('languagesBahasa-bahasa') then
table.insert (html, table.concat ({' collectiveTeks textkolektif ', language, '\"'})); -- for collective languages
else
table.insert (html, table.concat ({' Teks bahasa ', language, text'\"'})); -- for individual languages
end
table.insert (html, '>'); -- close the opening html tag
Baris 559 ⟶ 557:
end
if language_name:find ('languagesBahasa-bahasa') then
return table.concat ({'[[Category:ArticlesRencana withdengan textteks fromkolektif thedari bahasa ', language_name, ' collective]]'});
end
table.insert (cat, '[[Category:ArticlesRencana containingyang mengandungi teks bahasa ');
if 'enms' == code then
table.insert (cat, 'explicitlysecara citedjelas Englishmenyebut Bahasa Melayu]]');
elseif 'art' == code then
table.insert (cat, 'constructedyang dibina')
else
table.insert (cat, language_name .. ']]');
end
table.insert (cat, '-language text]]');
 
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, language_name'Transliterasi '); -- write afinish genericthe tool tip
if not language_name:find ('languagesBahasa-bahasa') then -- collective language names (plural 'languages' is part of the name)
table.insert (tout, '-languagebahasa ') -- skip this text (individual and macro languages only)
end
table.insert (tout, ' romanization'language_name); -- finishwrite thea generic tool tip; use romanization when neither script nor standard supplied
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 ('languagesBahasa-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
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 ('notiada textteks', args, template);
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 ('textteks hasmempunyai malformedpenanda markupcacat', args, template);
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 ('textteks hasmempunyai italicpenanda markupitalik', args, template);
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
 
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 ⟶ 789:
return text, tag;
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' == proto_param then
return true;
elseif 'no' == 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
 
Baris 829 ⟶ 799:
<includeonly>{{#invoke:lang|lang}}</includeonly>
 
parameters are receivedrecieved from the template's frame (parent frame)
 
]]
 
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 840 ⟶ 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 854 ⟶ 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 864 ⟶ 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 ({'invalid &#124;proto=: ', args.proto}), 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 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
(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 913 ⟶ 891:
args.text = invert_italics (args.text)
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 921 ⟶ 899:
 
return table.concat (out); -- put it all together and done
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
 
Baris 998 ⟶ 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 1,010 ⟶ 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,026 ⟶ 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,032 ⟶ 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,040 ⟶ 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,052 ⟶ 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,078 ⟶ 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,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
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 ('bahasaBahasa ' .. language_name, 'Bahasa ' .. language_name)); -- language name with wikilink
end
end
Baris 1,131 ⟶ 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,100:
translit_script_name = language_name; -- fall back on language name
end
translit_title = mw.title.makeTitle (0, table.concat ({'RomanizationPerumian ofuntuk ', translit_script_name})); -- make a title object
if translit_title.exists and ('no' ~= args.link) then
table.insert (out, make_wikilink ('RomanizationPerumian ofuntuk ' .. translit_script_name or language_name,'translit. 'romanized') .. ':'language_name)); -- make a wikilink if there is an article to link to
else
table.insert (out, 'romanized:<abbr title="transliterasi">translit.</abbr>'); -- else plaindefine the textabbreviation
end
table.insert (out, '&nbsp;</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, template'lang-xx');
end
end
Baris 1,166 ⟶ 1,122:
table.insert (out, '<small>');
if 'no' == args.link then
table.insert (out, '<abbr title="literalterjemahan translationliteral">lit.</abbr>');
else
table.insert (out, make_wikilink ('LiteralTerjemahan translationliteral', 'lit.'));
end
table.insert (out, "&nbsp;</small>");
Baris 1,179 ⟶ 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,218 ⟶ 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,244 ⟶ 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,302 ⟶ 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,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
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 ('bahasaBahasa ' .. language_name, 'Bahasa ' .. language_name); -- language name with wikilink
end
end
Baris 1,352 ⟶ 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,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
 
 
--[[--------------------------< 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,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
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,
 
--deprecated entry points:
code_from_name = tag_from_name, -- code is wrong; should be tag; these here to ease transition to the proper name
is_ietf_code = is_ietf_tag,
name_from_code = name_from_tag,
 
_code_from_name = _tag_from_name,
_is_ietf_code = _is_ietf_tag,
_name_from_code = _name_from_tag,
};