0
దిద్దుబాట్లు
చి (en:Module:Lang నుండి కూర్పులను దిగుమతి చేసాం) |
(sync from sandbox;) |
||
region: upper case
variant: lower case
private: lower case prefixed with -x-
]]
local function format_ietf_tag (code, script, region, variant, private)
local out = {};
if is_set (private) then
return table.concat ({code:lower(), 'x', private:lower()}, '-'); -- if private, all other tags ignored
end
table.insert (out, code:lower());
if is_set (script) then
table.insert (html, table.concat ({style_added, ' title=\"', language})); --start the title text
if language:find ('languages') then
table.insert (html, ' collective text
else
table.insert (html, ' language text
end
table.insert (html, '\">'); -- close the opening html tag
else
table.insert (html, table.concat ({style_added, '>'})); -- close the style attribute and close opening html tag
[[Category:Articles containing explicitly cited English-language text]]
for ISO 639-2 collective languages (and for 639-1 bh):
[[Category:Articles with text from the <language> languages collective]]
]=]
local function make_category (code, language_name, nocat, name_get)
local cat = {};
local retval;
if ((0 ~= namespace) or nocat) and not name_get then -- only categorize in article space
return ''; -- return empty string for concatenation
end
if language_name:find ('languages') then
--
retval = name_get and retval:gsub ('[%[%]]', '') or retval; -- when called from category_from_tag() strip wikilink markup to return plain-text category name
return retval;
end
table.insert (cat, '[[Category:Articles containing ');
if 'en' == code then
table.insert (cat, 'explicitly cited English');
else
table.insert (cat, language_name);
table.insert (cat, '-language text]]');
retval = name_get and retval:gsub ('[%[%]]', '') or retval; -- when called from category_from_tag() strip wikilink markup to return plain-text category name
return retval
end
end
--[[--------------------------< L A N G U A G E _ N A M E _ G E T >--------------------------------------------
common function to return language name from the data set according to IETF tag
returns language name
]]
local function language_name_get (ietf, code, variant)
if lang_data.override[ietf:lower()] then -- look for whole IETF tag in override table
return lang_data.override[ietf:lower()][1]; -- ietf:lower() because format_ietf_tag() returns mixed case
elseif lang_data.override[code] then -- not there so try basic language code
return lang_data.override[code][1];
elseif not is_set (variant) then -- shift to main code/name tables
if lang_name_table.lang[code] then
return lang_name_table.lang[code][1]; -- table entries sometimes have multiple names, always take the first one
end
else -- TODO: is this the right thing to do: take language display name from variants table?
if lang_name_table.variant[variant] then -- TODO: there is some discussion at Template talk:Lang about having a label parameter for use when variant name is not desired among other things
return lang_name_table.variant[variant]['descriptions'][1]; -- table entries sometimes have multiple names, always take the first one
end
end
end
--[[--------------------------< _ L A N G >--------------------------------------------------------------------
local out = {};
local language_name; -- used to make category names
local category_name; -- same as language_name except that it retains any parenthetical disambiguators (if any) from the data set
local subtags = {}; -- IETF subtags script, region, variant, and private
local code; -- the language code
end
args.code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant, subtags.private); -- format to recommended subtag styles
language_name = language_name_get (args.code, code, subtags.variant); -- get language name; try ietf tag first, then code w/o variant then code w/ variant
if 'invert' == args.italic and 'span' == tag then -- invert only supported for in-line content
end
args.code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant, subtags.private); -- format to recommended subtag styles
language_name = language_name_get (args.code, code, subtags.variant); -- get language name; try ietf tag first, then code w/o variant then code w/ variant
category_name = language_name; -- category names retain IANA parenthetical diambiguators (if any)
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, nil))
if is_set (args.translit) and not unicode.is_Latin (args.text) then -- transliteration (not supported in {{lang}}); not supported when args.text is wholly latn text (this is an imperfect test)
local function _is_ietf_tag (tag) -- entry point when this module is require()d into another
local c, s, r, v, p, err; -- code, script, region, variant, private, error message
c, s, r, v, p, err = get_ietf_parts (tag); -- disassemble tag into constituent part and validate
--[[--------------------------< _ N A M E _ F R O M _
Returns language name associated with IETF language tag if valid;
All code combinations supported by {{lang}} and the {{lang-xx}} templates are supported by this function.
local raw_code = args[1]; -- save a copy of the input IETF subtag
local link = 'yes' == args['link']; -- make a boolean
local label = args.label;
local code; -- the language code
local msg; -- gets an error message if IETF language tag is malformed or invalid
end
raw_code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant, subtags.private); -- format to recommended subtag styles; private omitted because private
language_name = language_name_get (raw_code, code, subtags.variant); -- get language name; try ietf tag first, then code w/o variant then code w/ variant
language_name = language_name:gsub ('%s+%b()', ''); -- remove IANA parenthetical disambiguators or qualifiers from names that have them
if link then -- when |link=yes, wikilink the language name
if language_name:find ('languages') then
language_name = make_wikilink (language_name, label);
elseif lang_data.article_name[code] then
language_name = make_wikilink (lang_data.article_name[code][1], label or language_name); -- language name with wikilink from override data
else
language_name = make_wikilink (language_name .. ' language', label or language_name); -- language name with wikilink
end
end
return language_name;
end
local function transl (frame)
return _transl (getArgs(frame));
end
--[[--------------------------< C A T E G O R Y _ F R O M _ T A G >--------------------------------------------
Returns category name associated with IETF language tag if valid; error message else
All code combinations supported by {{lang}} and the {{lang-xx}} templates are supported by this function.
Module entry point from another module
]]
local function _category_from_tag (args)
local subtags = {}; -- IETF subtags script, region, variant, and private
local raw_code = args[1]; -- save a copy of the input IETF subtag
local link = 'yes' == args['link']; -- make a boolean
local label = args.label;
local code; -- the language code
local msg; -- gets an error message if IETF language tag is malformed or invalid
local language_name = '';
code, subtags.script, subtags.region, subtags.variant, subtags.private, msg = get_ietf_parts (raw_code);
if msg then
local template = (args['template'] and table.concat ({'{{', 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
raw_code = format_ietf_tag (code, subtags.script, subtags.region, subtags.variant, subtags.private); -- format to recommended subtag styles; private omitted because private
language_name = language_name_get (raw_code, code, subtags.variant); -- get language name; try ietf tag first, then code w/o variant then code w/ variant
return make_category (code, language_name, nil, true)
end
--[[--------------------------< C A T E G O R Y _ F R O M _ T A G >--------------------------------------------
Module entry point from an {{#invoke:}}
]]
local function category_from_tag (frame) -- entry point from an {{#invoke:Lang|category_from_tag|<ietf tag>|template=<template name>}}
return _category_from_tag (getArgs (frame)); -- pass-on the args table, nothing else; getArgs() so we also get parent frame
end
return {
category_from_tag = category_from_tag,
lang = lang, -- entry point for {{lang}}
lang_xx_inherit = lang_xx_inherit, -- entry points for {{lang-??}}
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,
_lang_xx_inherit = _lang_xx_inherit,
_lang_xx_italic = _lang_xx_italic,
|
దిద్దుబాట్లు