end
end
return add_ietf_error_msg (name, ietf_err, hide, nocat), true; -- return language name with ietf error message if any; true because we found a code
end  
----------------------------< _ N A M E _ F R O M _ C O D E >------------------------------------------------  
searches through the ISO 639 language tables for a name that matches the supplied code. on success returns first
language name that matches code from template perhaps with an error message and a second return value of true;
on failure returns an error message and a second return value of nil. The second return value is a return value
used by is_code  
looks first in the override data and then sequentially in the 639-1, -2, -3, and -5 data  
local function _name_from_code
local args = getArgs;
local hide = 'yes' == args['hide-err']; -- suppress error messages and error categorization
local nocat = 'no' == args.cat; -- suppress error categorization (primarily for demo use)  
if not args[1] then -- if code not provided in the template call
return error_msg ('required', '', hide, nocat); -- abandon
end  
local name; -- the retrieved language name and / or error message
local found; -- set to true when language name is found  
for _, part in ipairs (parts) do
name, found = name_from_code_common (args, part[1], part[2]);
if found then
return name, true; -- second retval for is_name
end
end  
return error_msg ('not_found', {args[1], '1, -2, -2B, -3, -5'}, hide, nocat); -- here when code (args[1]) is not found in the data tables
end  
----------------------------< N A M E _ F R O M _ C O D E >--------------------------------------------------  
template entry point; returns first language name that matches code from template or an error message
looks first in the override data and then sequentially in the 639-1, -2, -3, and -5 data  
local function name_from_code
local ret_val = _name_from_code ; -- ignore second return value
return ret_val; -- return language name and / or error message
end  
----------------------------< I S _ C O D E >----------------------------------------------------------------  
template entry point; returns true if language code maps to a language name; intended as a replacement for:  
Instead of that expensive parser function call use this function:  
on success, returns true; nil else  
local function is_code
local _, exists;
_, exists = _name_from_code ; -- ignore name/error message return; <exists> is true when name found for code; nil else
return exists;
end  
----------------------------< N A M E _ F R O M _ C O D E _ 1 >----------------------------------------------  
template entry point; returns first language name that matches ISO 639-1 code from template or an error message  
local function name_from_code_1
local args = getArgs ;
local retval = name_from_code_common (args, parts[1][1], parts[1][2]); -- suppress second return value
return retval;
end  
----------------------------< N A M E _ F R O M _ C O D E _ 2 >----------------------------------------------  
template entry point; returns first language name that matches ISO 639-2 code from template or an error message  
local function name_from_code_2
local args = getArgs ;
local retval = name_from_code_common (args, parts[2][1], parts[2][2]); -- suppress second return value
return retval;
end  
----------------------------< N A M E _ F R O M _ C O D E _ 2 B >--------------------------------------------  
template entry point; returns first language name that matches ISO 639-2 code from template or an error message  
local function name_from_code_2B
local args = getArgs ;
local retval = name_from_code_common (args, parts[3][1], parts[3][2]); -- suppress second return value
return retval;
end  
----------------------------< N A M E _ F R O M _ C O D E _ 3 >----------------------------------------------  
template entry point; returns first language name that matches ISO 639-3 code from template or an error message  
local function name_from_code_3
local args = getArgs ;
local retval = name_from_code_common (args, parts[4][1], parts[4][2]); -- suppress second return value
return retval;
end  
----------------------------< N A M E _ F R O M _ C O D E _ 5 >----------------------------------------------  
template entry point; returns first language name that matches ISO 639-5 code from template or an error message  
local function name_from_code_5
local args = getArgs ;
local retval = name_from_code_common (args, parts[5][1], parts[5][2]); -- index [4] -> part 5 because there is no part 4; suppress second return value
return retval;
end  
----------------------------< N A M E _ I N _ P A R T _ C O D E _ G E T >------------------------------------  
indexes into the <name_data> using <name> and extracts the language code assigned to <part> (1, 2, 2B, 3, 5).
attempts to index override data first; returns code on success, nil else  
local function name_in_part_code_get (name, part, part_idx, name_data)
return name_data[name] and (
name_data[name][part_idx+5] or -- see if the name exists in the part's override table
name_data[name][part_idx] or -- see if the name exists in the part's main table
name_data[name][part_idx+10] -- see if the name exists in the part's deprecated table
);
end  
----------------------------< _ C O D E _ F R O M _ N A M E >------------------------------------------------  
module entry point; returns ISO 639-1, -2, -2B, -3, or -5 code associated with language name according to part
(1, 2, 2B, 3, 5) argument; when part is not provided scans 1, 2, 2B, 3, 5 and returns first code  
override data are examined first  
<args> is arguments from getArgs  
local function _code_from_name (args)
local hide = 'yes' == args['hide-err']; -- suppress error messages and error categorization
local nocat = 'no' == args.cat; -- suppress error categorization (primarily for demo use)  
if not args[1] then
return error_msg ('name', '', hide, nocat); -- abandon when language name missing
end  
local name = args[1]; -- used in error messaging
local lc_name = name:gsub(' +', ' '); -- strip extraneous space characters
lc_name = mw.ustring.lower (lc_name); -- lowercase version of name for indexing into the data table  
local part_idx;
local part = args[2];
if part then
part_idx = get_part_index (part);
if not part_idx then
return error_msg ('not_part', part, hide, nocat); -- abandon; args[2] is not a valid ISO 639 part
end
end  
-- local name_data = mw.loadData ('Module:Language/data/ISO 639 name to code'); -- ISO 639 language names to code table
local name_data = mw.loadData ('Module:Language/data/ISO 639 name to code/sandbox'); -- ISO 639 language names to code table  
local code;  
if part then
code = name_in_part_code_get (lc_name, part, part_idx, name_data); -- search the specified override table + part table
else
for part_idx, part_tag in ipairs ({'1', '2', '2B', '3', '5'}) do -- no part provided, spin through all parts override first and get the first available code
code = name_in_part_code_get (lc_name, part_tag, part_idx, name_data);
if code then -- nil when specified <part> does not have code for specified language <name>
break; -- when code is not nil, done
end
end
end  
if code then
return code, true;
end
return error_msg ('not_found', {name, part or '1, -2, -2B, -3, -5'}, hide, nocat), false;
end  
--[[--------------------------< C O D E _ F R O M _ N A M E >--------------------------------------------------  
template entry point; returns ISO 639-1, -2, -2B, -3, or -5 code associated with language name according to part
(1, 2, 2B, 3, 5) argument; when part is not provided scans 1, 2, 2B, 3, 5 and returns first code  
override data are examined first  
args[1] is language name
args[2] is ISO 639 part  
local function code_from_name
local args = getArgs;
local result, _ = _code_from_name (args); -- suppress true/false return used by is_name
return result;
end  
--[[--------------------------< I S _ N A M E >----------------------------------------------------------------