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  
----------------------------< _ I S O _ 6 3 9 _ C O D E _ T O _ N A M 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 iso_639_code_exists  
looks first in the override data and then sequentially in the 639-1, -2, -3, and -5 data  
local function _iso_639_code_to_name
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 = iso_639_code_to_name_common (args, part[1], part[2]);
if found then
return name, true; -- second retval for iso_639_name_exists
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  
----------------------------< I S O _ 6 3 9 _ C O D E _ T O _ N A M 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 iso_639_code_to_name
local ret_val = _iso_639_code_to_name ; -- ignore second return value
return ret_val; -- return language name and / or error message
end  
----------------------------< I S O _ 6 3 9 _ C O D E _ E X I S T S >----------------------------------------  
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 iso_639_code_exists
local _, exists;
_, exists = _iso_639_code_to_name ; -- ignore name/error message return; <exists> is true when name found for code; nil else
return exists;
end  
----------------------------< I S O _ 6 3 9 _ C O D E _ 1 _ T O _ N A M E >----------------------------------  
template entry point; returns first language name that matches ISO 639-1 code from template or an error message  
local function iso_639_code_1_to_name
local args = getArgs ;
local retval = iso_639_code_to_name_common (args, parts[1][1], parts[1][2]); -- suppress second return value
return retval;
end  
----------------------------< I S O _ 6 3 9 _ C O D E _ 2 _ T O _ N A M E >----------------------------------  
template entry point; returns first language name that matches ISO 639-2 code from template or an error message  
local function iso_639_code_2_to_name
local args = getArgs ;
local retval = iso_639_code_to_name_common (args, parts[2][1], parts[2][2]); -- suppress second return value
return retval;
end  
----------------------------< I S O _ 6 3 9 _ C O D E _ 2 B _ T O _ N A M E >--------------------------------  
template entry point; returns first language name that matches ISO 639-2 code from template or an error message  
local function iso_639_code_2B_to_name
local args = getArgs ;
local retval = iso_639_code_to_name_common (args, parts[3][1], parts[3][2]); -- suppress second return value
return retval;
end  
----------------------------< I S O _ 6 3 9 _ C O D E _ 3 _ T O _ N A M E >----------------------------------  
template entry point; returns first language name that matches ISO 639-3 code from template or an error message  
local function iso_639_code_3_to_name
local args = getArgs ;
local retval = iso_639_code_to_name_common (args, parts[4][1], parts[4][2]); -- suppress second return value
return retval;
end  
----------------------------< I S O _ 6 3 9 _ C O D E _ 5 _ T O _ N A M E >----------------------------------  
template entry point; returns first language name that matches ISO 639-5 code from template or an error message  
local function iso_639_code_5_to_name
local args = getArgs ;
local retval = iso_639_code_to_name_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  
----------------------------< _ I S O _ 6 3 9 _ N A M E _ T O _ C O D 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 _iso_639_name_to_code (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(' +', ' '):lower; -- lowercase version of name for indexing into the data table; strip extraneous space characters  
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  
--[[--------------------------< I S O _ 6 3 9 _ N A M E _ T O _ C O D 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 iso_639_name_to_code
local args = getArgs;
local result, _ = _iso_639_name_to_code (args); -- suppress true/false return used by iso_639_name_exists
return result;
end