Jump to content

Module:Lang: Difference between revisions

sync from sandbox;
m (1 revision imported)
(sync from sandbox;)
Line 367: Line 367:
if not in_array (table.concat ({code, '-', script}), lang_name_table.variant[variant]['prefixes']) then
if not in_array (table.concat ({code, '-', script}), lang_name_table.variant[variant]['prefixes']) then
return code, script, region, nil, nil, table.concat ({'unrecognized variant: ', variant, ' for code-script pair: ', code, '-', script});
return code, script, region, nil, nil, table.concat ({'unrecognized variant: ', variant, ' for code-script pair: ', code, '-', script});
end
elseif is_set (region) then -- if region set, there are some prefixes that require lang code and region (en-CA-newfound)
if not in_array (code, lang_name_table.variant[variant]['prefixes']) then -- first see if lang code is all that's required (en-oxendict though en-GB-oxendict is preferred)
if not in_array (table.concat ({code, '-', region}), lang_name_table.variant[variant]['prefixes']) then -- now try for lang code and region (en-CA-newfound)
return code, script, region, nil, nil, table.concat ({'unrecognized variant: ', variant, ' for code-region pair: ', code, '-', region});
end
end
end
else
else
Line 531: Line 537:
table.insert (html, '‎'); -- make sure the browser knows that we're at the end of the rtl
table.insert (html, '‎'); -- make sure the browser knows that we're at the end of the rtl
end
end
return table.concat (html); -- put it all together and done
return table.concat (html); -- put it all together and done
end
end
Line 560: Line 565:
if language_name:find ('languages') then
if language_name:find ('languages') then
return table.concat ({'[[Category:Articles with text from the ', language_name, ' collective]]'});
-- return table.concat ({'[[Category:Articles with text from the ', language_name, ' collective]]'});
return table.concat ({'[[Category:Articles with text from ', language_name, ']]'});
end
end
Line 822: Line 828:




--[[--------------------------< L A N G >----------------------------------------------------------------------
--[[--------------------------< _ L A N G >--------------------------------------------------------------------


entry point for {{lang}}
entry point for {{lang}}
Line 1,278: Line 1,284:
local function _is_ietf_tag (tag) -- entry point when this module is require()d into another
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, private, error message
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
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
return ((c and not err) and true) or nil; -- return true when code portion has a value without error message; nil else
end
end
Line 1,290: Line 1,296:
]]
]]


local function is_ietf_tag (frame) -- entry point from an {{#invoke:Lang|is_ietf_tag|<ietf tag>}}
local function is_ietf_tag (frame)
return _is_ietf_tag (frame.args[1]); -- frame.args[1] is the ietf language tag
return _is_ietf_tag (getArgs(frame)[1]); -- args[1] is the ietf language tag to be tested; getArgs() so we also get parent frame
end
end


Line 1,339: Line 1,345:
if link then -- when |link=yes, wikilink the language name
if link then -- when |link=yes, wikilink the language name
if language_name:find ('languages') then
if language_name:find ('languages') then
return make_wikilink (language_name); -- collective language name uses simple wikilink
language_name = make_wikilink (language_name); -- collective language name uses simple wikilink
elseif lang_data.article_name[code] then
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
language_name = make_wikilink (lang_data.article_name[code][1], language_name); -- language name with wikilink from override data
else
else
return make_wikilink (language_name .. ' language', language_name); -- language name with wikilink
language_name = make_wikilink (language_name .. ' language', language_name); -- language name with wikilink
end
end
end
end
Line 1,352: Line 1,358:




--[[--------------------------< N A M E _ F R O M _ C O D E >--------------------------------------------------
--[[--------------------------< N A M E _ F R O M _ T A G >----------------------------------------------------


Module entry point from an {{#invoke:}}
Module entry point from an {{#invoke:}}
Line 1,359: Line 1,365:


local function name_from_tag (frame) -- entry point from an {{#invoke:Lang|name_from_tag|<ietf tag>|link=<yes>|template=<template name>}}
local function name_from_tag (frame) -- entry point from an {{#invoke:Lang|name_from_tag|<ietf tag>|link=<yes>|template=<template name>}}
return _name_from_tag (frame.args); -- pass-on the args table, nothing else
return _name_from_tag (getArgs(frame)) -- pass-on the args table, nothing else; getArgs() so we also get parent frame
end
end


Line 1,379: Line 1,385:
local data = mw.loadData ('Module:Lang/name to tag'); -- get the reversed data tables
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 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
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
if tag then
return tag; -- language name found so return tag and done
return tag, true; -- language name found so return tag and done; second return used by is_lang_name()
else
else
msg = 'language: ' .. args[1] .. ' not found' -- language name not found, error message
msg = 'language: ' .. args[1] .. ' not found' -- language name not found, error message
Line 1,405: Line 1,411:


local function tag_from_name (frame) -- entry point from an {{#invoke:Lang|tag_from_name|<language name>|link=<yes>|template=<template name>}}
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
local result, _ = _tag_from_name (getArgs(frame)) -- pass-on the args table, nothing else; getArgs() so we also get parent frame; supress second return used by is_lang_name()
return result;
end
 
 
--[[--------------------------< I S _ L A N G _ N A M E >------------------------------------------------------
 
Module entry point from an {{#invoke:}}
 
]]
 
local function is_lang_name (frame)
local _, result = _tag_from_name (getArgs(frame)) -- pass-on the args table, nothing else; getArgs() so we also get parent frame; supress second return used by tag_from_name()
return result and true or nil;
end
end


Line 1,484: Line 1,503:


local function transl (frame)
local function transl (frame)
local args = getArgs(frame); -- no {{#invoke:}} parameters
return _transl (getArgs(frame));
return _transl (args);
end
end


Line 1,497: Line 1,515:
lang_xx_italic = lang_xx_italic,
lang_xx_italic = lang_xx_italic,
is_ietf_tag = is_ietf_tag,
is_ietf_tag = is_ietf_tag,
is_lang_name = is_lang_name,
tag_from_name = tag_from_name, -- returns ietf tag associated with language name
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
name_from_tag = name_from_tag, -- used for template documentation; possible use in ISO 639 name from code templates
Anonymous user