Module:ISO 639 name/sandbox
![]() | This is the module sandbox page for Module:ISO 639 name (diff). See also the companion subpage for test cases (run). |
![]() | This Lua module is used on approximately 20,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
Module:ISO 639 name implements:
{{ISO 639 name}}
{{Lang2iso}}
Data mapping
[edit]For code-to-name mapping, this module uses data from:
- Module:ISO 639 name/ISO 639-1 – from IANA language-subtag-registry file; this data used only for ISO 639-1 language codes / names listed there
- Module:ISO 639 name/ISO 639-2 – from Codes for the Representation of Names of Languages
- Module:ISO 639 name/ISO 639-2B – from Codes for the Representation of Names of Languages
- Module:ISO 639 name/ISO 639-3 – from sil.org UTF-8 Complete Code Tables Set
- Module:ISO 639 name/ISO 639-5 – from Codes for the Representation of Names of Languages Part 5
- Module:ISO 639 name/ISO 639 deprecated – from ISO 639-2/RA Change Notice and ISO 639-5 Change Notice includes:
- Module:ISO 639 name/ISO 639-3 (dep) – from sil.org UTF-8 Complete Code Tables Set (Retirements)
- Module:ISO 639 name/ISO 639 override – code to name mapping where the name is different from the name in the ISO 639 standard
For name-to-code mapping, this module uses data from:
- Module:ISO 639 name/ISO 639 name to code – names and codes extracted from the code-to-name data set above
Testcases
[edit]- Module:ISO 639 name/testcases (run)
- code_to_name()
- Module:ISO 639 name/testcases/ISO 639-1 name from code (run)
- Module:ISO 639 name/testcases/ISO 639-2 name from code (run)
- Module:ISO 639 name/testcases/ISO 639-3-1 name from code (A–H) (run)
- Module:ISO 639 name/testcases/ISO 639-3-2 name from code (I–N) (run)
- Module:ISO 639 name/testcases/ISO 639-3-3 name from code (O–Z) (run)
- Module:ISO 639 name/testcases/ISO 639-5 name from code (run)
- Module:ISO 639 name/testcases/ISO 639 deprecated name from code (run)
- name_to_code()
- Module:ISO 639 name/testcases/ISO 639-1 code from name (run)
- Module:ISO 639 name/testcases/ISO 639-2 code from name (run)
- Module:ISO 639 name/testcases/ISO 639-3-1 code from name (A–H) (run)
- Module:ISO 639 name/testcases/ISO 639-3-2 code from name (I–N) (run)
- Module:ISO 639 name/testcases/ISO 639-3-3 code from name (O–Z) (run)
- Module:ISO 639 name/testcases/ISO 639-5 code from name (run)
- Module:ISO 639 name/testcases/ISO 639 deprecated code from name (run)
Tracking categories
[edit]iso_639_code_exists
[edit]Returns true
when <code>
is found in one of the ISO 639-1, -2, -3, -5, or override tables; returns nil else.
Useage:
{{#invoke:ISO 639 name|iso_639_code_exists|<code>}}
Examples:
- without required
<code>
:{{#invoke:ISO 639 name|iso_639_code_exists}}
→
- with valid
<code>
:{{#invoke:ISO 639 name|iso_639_code_exists|nav}}
→ true
- with invalid
<code>
:{{#invoke:ISO 639 name|iso_639_code_exists|xx}}
→
iso_639_code_to_name
[edit]Returns language name associated with <code>
. May return an error message with or without a language name.
Optional parameters:
|hide-err=yes
: suppresses error messages|link=yes
: creates link to en.wiki article about the language|label=<label text>
– requires|link=yes
; label for the language-name link:[[<language name> language|<label text>]]
|raw=yes
: queries part tables only; returns language name as defined in the base data tables without the removal of disambiguation information
Examples:
- without required
<code>
:{{#invoke:ISO 639 name|iso_639_code_to_name}}
→ error: ISO 639 code is required (help)
- with valid
<code>
:{{#invoke:ISO 639 name|iso_639_code_to_name|nav}}
→ Navajo
- with invalid
<code>
:{{#invoke:ISO 639 name|iso_639_code_to_name|xx}}
→ error: xx not found in ISO 639-1, -2, -2B, -3, -5 list (help)
- with invalid
<code>
(IETF language tag):{{#invoke:ISO 639 name|iso_639_code_to_name|nv-Latn}}
→ Navajo error: nv-Latn is an IETF tag (help)
- with invalid
<code>
, error message suppressed:{{#invoke:ISO 639 name|iso_639_code_to_name|nv-Latn|hide-err=yes}}
→ Navajo
- linked:
{{#invoke:ISO 639 name|iso_639_code_to_name|nav|link=yes}}
→ Navajo
- linked with alternate spelling:
{{#invoke:ISO 639 name|iso_639_code_to_name|nav|link=yes|label=Navaho}}
→ Navaho
- ISO 639-1 code
el
is normally overridden by a setting in Module:ISO 639 name/ISO_639_override:{{#invoke:ISO 639 name|iso_639_code_to_name|el}}
→ Greek
- ISO 639-1 code
el
with override suppressed:{{#invoke:ISO 639 name|iso_639_code_to_name|el|raw=yes}}
→ Modern Greek (1453-)
- ISO 639-3 code
ina
name has disambiguation that is normally suppressed:{{#invoke:ISO 639 name|iso_639_code_to_name|ina}}
→ Interlingua
- ISO 639-3 code
ina
with disambiguation:{{#invoke:ISO 639 name|iso_639_code_to_name|ina|raw=yes}}
→ Interlingua (International Auxiliary Language Association)
iso_639_code_1_to_name
[edit]Same as iso_639_code_to_name
except that <code>
must be an ISO 639-1 code; search is constrained to Module:ISO 639 name/ISO 639 override and Module:ISO 639 name/ISO 639-1.
Example:
- with valid
<code>
:{{#invoke:ISO 639 name|iso_639_code_1_to_name|nv}}
→ Navajo
- with invalid
<code>
:{{#invoke:ISO 639 name|iso_639_code_1_to_name|xx}}
→ error: xx not found in ISO 639-1 list (help)
iso_639_code_2_to_name
[edit]Same as iso_639_code_to_name
except that <code>
must be an ISO 639-2 code; search is constrained to Module:ISO 639 name/ISO 639 override and Module:ISO 639 name/ISO 639-2.
Example:
- with valid
<code>
:{{#invoke:ISO 639 name|iso_639_code_2_to_name|apa}}
→ Apache languages
- with invalid
<code>
:{{#invoke:ISO 639 name|iso_639_code_2_to_name|xxx}}
→ error: xxx not found in ISO 639-2 list (help)
iso_639_code_2B_to_name
[edit]Same as iso_639_code_to_name
except that <code>
must be an ISO 639-2B code; search is constrained to Module:ISO 639 name/ISO 639 override and Module:ISO 639 name/ISO 639-2B.
Example:
- with valid
<code>
:{{#invoke:ISO 639 name|iso_639_code_2B_to_name|ice}}
→ Icelandic
- with invalid
<code>
:{{#invoke:ISO 639 name|iso_639_code_2B_to_name|xxx}}
→ error: xxx not found in ISO 639-2B list (help)
iso_639_code_3_to_name
[edit]Same as iso_639_code_to_name
except that <code>
must be an ISO 639-3 code; search is constrained to Module:ISO 639 name/ISO 639 override and Module:ISO 639 name/ISO 639-3.
Example:
- with valid
<code>
:{{#invoke:ISO 639 name|iso_639_code_3_to_name|nav}}
→ Navaho
- with invalid
<code>
:{{#invoke:ISO 639 name|iso_639_code_3_to_name|xxx}}
→ error: xxx not found in ISO 639-3 list (help)
iso_639_code_5_to_name
[edit]Same as iso_639_code_to_name
except that <code>
must be an ISO 639-5 code; search is constrained to Module:ISO 639 name/ISO 639 override and Module:ISO 639 name/ISO 639-5.
Example:
- with valid
<code>
:{{#invoke:ISO 639 name|iso_639_code_5_to_name|apa}}
→ Apache languages
- with invalid
<code>
:{{#invoke:ISO 639 name|iso_639_code_5_to_name|xxx}}
→ error: xxx not found in ISO 639-5 list (help)
iso_639_name_exists
[edit]Returns true
when <language name>
is found in one of the ISO 639-1, -2, -3, -5, or override tables; returns nil else.
Useage:
{{#invoke:ISO 639 name|iso_639_name_exists|<language name>}}
Examples:
- without required
<language name>
:{{#invoke:ISO 639 name|iso_639_name_exists}}
→
- with valid
<language name>
:{{#invoke:ISO 639 name|iso_639_name_exists|french}}
→ true
- with invalid
<language name>
:{{#invoke:ISO 639 name|iso_639_name_exists|fr}}
→
iso_639_name_to_code
[edit]Returns ISO 639 language code associated with <language name>
. May return an error message with or without a language name.
This function may not be particularly useful because, except for case, <language name>
must exactly match the name in the data tables.
Optional parameters:
<part>
(second positional parameter) – limits return to codes from the specified<part>
(1
,2
,3
,5
), override table first then the appropriate data table; when not supplied, this function searches in order part 1 to part 5. The search stops when a match is found.|hide-err=yes
: suppresses error messages
Examples:
- without
<part>
, with ISO 639-5 name:{{#invoke:ISO 639 name|iso_639_name_to_code|North Germanic languages}}
→ gmq
- with
<part>
:{{#invoke:ISO 639 name|iso_639_name_to_code|Navajo|2}}
→ nav
iso_639
[edit]When given an ISO 639 language code, return the associated language name; when given a language name, returns the associated ISO 639 language code. May return an error message with or without a language code/name.
This function may not be particularly useful because, except for case, a provided <language name>
must exactly match the name in the data tables.
Optional parameters:
<part>
(second positional parameter) – limits return to codes/names from the specified<part>
(1
,2
,3
,5
), override table first then the appropriate data table; when not supplied, this function searches in order part 1 to part 5. The search stops when a match is found.|hide-err=yes
: suppresses error messages
Examples:
- without
<part>
, with ISO 639-5 code:{{#invoke:ISO 639 name|iso_639|gmq}}
→ North Germanic languages
- without
<part>
, with ISO 639-5 name:{{#invoke:ISO 639 name|iso_639|North Germanic languages}}
→ gmq
- with
<part>
and<code>
:{{#invoke:ISO 639 name|iso_639|nav|2}}
→ Navajo
- with
<part>
and<name>
:{{#invoke:ISO 639 name|iso_639|Navaho|2}}
→ nav
require('strict');localgetArgs=require('Module:Arguments').getArgs;localoverride_data=mw.loadData('Module:ISO 639 name/ISO 639 override');localdeprecated_data=mw.loadData('Module:ISO 639 name/ISO 639 deprecated');localparts={{'Module:ISO 639 name/ISO 639-1','1'},{'Module:ISO 639 name/ISO 639-2','2'},{'Module:ISO 639 name/ISO 639-2B','2B'},{'Module:ISO 639 name/ISO 639-3','3'},{'Module:ISO 639 name/ISO 639-5','5'},}--[[--------------------------< E R R O R _ M E S S A G E S >--------------------------------------------------]]localerror_messages={['err_msg']='<span style="font-size:100%;" class="error show_639_err_msgs">error: $1 ([[Template:ISO 639 name|help]])</span>',['err_text']={-- error messages used only in the code to name functions['ietf']='$1 is an IETF tag',-- $1 is the ietf tag['required']='ISO 639$1 code is required',-- $1 is the 639 '-1', '-2', '-3', '-5' part suffix; may be empty string-- code to name functions and iso_639_name_to_code()['not_found']='$1 not found in ISO 639-$2 list',-- $1 is code or language name; $2 is 639 part suffix(es)-- iso_639_name_to_code() only['name']='language name required',['not_part']='$1 not an ISO 639 part',-- $1 is invalid 639 suffix (without hyphen)['code_name']='language code or name required',-- iso_639() only}}localerror_cat='[[Category:ISO 639 name template errors]]';--[[--------------------------< S U B S T I T U T E >----------------------------------------------------------Populates numbered arguments in a message string using an argument table.]]localfunctionsubstitute(msg,args)returnargsandmw.message.newRawMessage(msg,args):plain()ormsg;end--[[--------------------------< E R R O R _ M S G >------------------------------------------------------------create an error message]]localfunctionerror_msg(msg,arg,hide,nocat)localretval='';ifnothidethenretval=substitute(error_messages.err_msg,substitute(error_messages.err_text[msg],arg));retval=nocatandretvalor(retval..error_cat);endreturnretvalend--[[--------------------------< I S _ S E T >------------------------------------------------------------------Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string.]]localfunctionis_set(var)returnnot(var==nilorvar=='');end--[=[-------------------------< M A K E _ W I K I L I N K >----------------------------------------------------Makes a wikilink; when both link and display text is provided, returns a wikilink in the form [[L|D]]; if onlylink is provided, returns a wikilink in the form [[L]]; if neither are provided or link is omitted, returns anempty string.]=]localfunctionmake_wikilink(link,display)ifis_set(link)thenifis_set(display)thenreturntable.concat({'[[',link,'|',display,']]'});elsereturntable.concat({'[[',link,']]'});endelsereturn'';endend--[[--------------------------< L A N G _ N A M E _ G E T >----------------------------------------------------returns first listed language name for code from data{} table; strips parenthetical disambiguation; wikilinks tothe language article if link is true; returns nil else]]localfunctionlang_name_get(code,data,link,label,raw)localname;ifdata[code]then-- name = raw and data[code][1] or data[code][1]:gsub ('%s*%b()', ''); -- get the name; strip parenthetical disambiguators if any when <raw> is falseifrawthenname=data[code][1];elsename=data[code][1]:gsub('%s*%b()','');-- strip parenthetical disambiguators if anyname=name:gsub('([^,]-), +(.+)','%2 %1');-- if inverted, uninvertendiflinkthen-- make a link to the language article?ifname:find('languages')orname:find('[Ll]anguage$')thenname=make_wikilink(name,label);-- simple wikilink for collective languages or langauges ending in 'Language' unless there is a labelelseifoverride_data.article_name[code]thenname=make_wikilink(override_data.article_name[code][1],labelorname);-- language name or label with wikilink from override dataelsename=make_wikilink(name..' language',labelorname);-- [[name language|name]] or [[name language|label]]endendreturnname;endend--[[--------------------------< A D D _ I E T F _ E R R O R _ M S G >------------------------------------------assembles return-text (language code, language name, or error message) with IETF error message into properlyformatted readable text|hide-err=yes suppresses error message and category|cat=no supresses category]]localfunctionadd_ietf_error_msg(text,ietf_err,hide,nocat)ifhidethenietf_err='';endifnotnocatthen-- |cat= empty or omitted -> nocat=falsenocat=''==ietf_err;-- spoof; don't add cat when no errorendreturntable.concat({-- tack on ietf error message if one existstext,-- code name, language name, or error message''~=ietf_errand' 'or'',-- needs a space when ietf_err is not emptyietf_err,nocatand''orerror_cat,-- add error category when |cat=<aynthing but 'no'>});end--[[--------------------------< G E T _ P A R T _ I N D E X >--------------------------------------------------gets index suitable for parts{} table from ISO 639-<part> (usually args[2])return valid index [1] - [5]; nil else 1 <- part ['1'] 2 <- part ['2'] -- this is part 2T 3 <- part ['2B'] 4 <- part ['3'] nil <- part ['4'] -- there is no part 4 5 <- part ['5']]]localfunctionget_part_index(part)return({['1']=1,['2']=2,['2B']=3,['3']=4,['4']=nil,['5']=5})[part]end--[[--------------------------< I S O _ 6 3 9 _ C O D E _ T O _ N A M E _ C O M M O N >------------------------this is code that is common to all of the iso_639_code_n_to_name() functions which serve only as template entrypoints to provide the frame, the name of the appropriate data source, and to identify which 639 part applies.this function returns a language name or an error message. data is searched in this order: part-specific override data -> standard part data -> part-specific deprecated dataa second retval used by _iso_639_code_to_name() is true when a code is found; nil else]]localfunctioniso_639_code_to_name_common(args,source,part)localhide='yes'==args['hide-err'];-- suppress error messages and error categorizationlocalnocat='no'==args.cat;-- suppress error categorization (primarily for demo use)localraw='yes'==args.raw;-- disable override and dab removallocaldata;-- one of the override or part tableslocalname;-- holds language name from dataifnotargs[1]then-- if code not provided in the template callreturnerror_msg('required','-'..part,hide,nocat);-- abandonendlocalcode;-- used for error messaginglocalietf_err;-- holds an error message when args[1] (language code) is in IETF tag form (may or may not be a valid IETF tag)code,ietf_err=args[1]:gsub('(.-)%-.*','%1');-- strip ietf subtags; ietf_err is non-zero when subtags are strippedietf_err=(0~=ietf_err)anderror_msg('ietf',args[1],hide,nocat)or'';-- when tags are stripped create an error message; empty string for concatenation elseifnotrawthen-- when raw is true, fetch name as is from part data; ignore overridedata=override_data['override_'..part];-- get override data for this partname=lang_name_get(code:lower(),data,args.link,args.label,raw);-- get override language name if there is oneendifnotnamethendata=mw.loadData(source);-- get the data for this ISO 639 partname=lang_name_get(code:lower(),data,args.link,args.label,raw);-- get language name if there is oneendifnotnamethen-- TODO: do something special to indicate when a name is fetched from deprecated data?data=deprecated_data['deprecated_'..part];-- get deprecated data for this partname=lang_name_get(code:lower(),data,args.link,args.label,raw);-- get deprecated language name if there is oneifnotnamethenreturnerror_msg('not_found',{code,part},hide,nocat);-- code not found, return error messageendendreturnadd_ietf_error_msg(name,ietf_err,hide,nocat),true;-- return language name with ietf error message if any; true because we found a codeend--[[--------------------------< _ 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 firstlanguage name that matches code from template frame 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 valueused by iso_639_code_exists()looks first in the override data and then sequentially in the 639-1, -2, -3, and -5 data]]localfunction_iso_639_code_to_name(frame)localargs=getArgs(frame);localhide='yes'==args['hide-err'];-- suppress error messages and error categorizationlocalnocat='no'==args.cat;-- suppress error categorization (primarily for demo use)ifnotargs[1]then-- if code not provided in the template callreturnerror_msg('required','',hide,nocat);-- abandonendlocalname;-- the retrieved language name and / or error messagelocalfound;-- set to true when language name is foundfor_,partinipairs(parts)doname,found=iso_639_code_to_name_common(args,part[1],part[2]);iffoundthenreturnname,true;-- second retval for iso_639_name_exists()endendreturnerror_msg('not_found',{args[1],'1, -2, -2B, -3, -5'},hide,nocat);-- here when code (args[1]) is not found in the data tablesend--[[--------------------------< 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 frame or an error messagelooks first in the override data and then sequentially in the 639-1, -2, -3, and -5 data]]localfunctioniso_639_code_to_name(frame)localret_val=_iso_639_code_to_name(frame);-- ignore second return valuereturnret_val;-- return language name and / or error messageend--[[--------------------------< 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: {{#exist:Template:ISO 639 name <code>|<exists>|<doesn't exist>}}Instead of that expensive parser function call use this function: {{#if:{{#invoke:ISO 639 name|iso_639_code_exists|<code>}}|<exists>|<doesn't exist>}}on success, returns true; nil else]]localfunctioniso_639_code_exists(frame)local_,exists;_,exists=_iso_639_code_to_name(frame);-- ignore name/error message return; <exists> is true when name found for code; nil elsereturnexists;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 frame or an error message]]localfunctioniso_639_code_1_to_name(frame)localargs=getArgs(frame);localretval=iso_639_code_to_name_common(args,parts[1][1],parts[1][2]);-- suppress second return valuereturnretval;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 frame or an error message]]localfunctioniso_639_code_2_to_name(frame)localargs=getArgs(frame);localretval=iso_639_code_to_name_common(args,parts[2][1],parts[2][2]);-- suppress second return valuereturnretval;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 frame or an error message]]localfunctioniso_639_code_2B_to_name(frame)localargs=getArgs(frame);localretval=iso_639_code_to_name_common(args,parts[3][1],parts[3][2]);-- suppress second return valuereturnretval;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 frame or an error message]]localfunctioniso_639_code_3_to_name(frame)localargs=getArgs(frame);localretval=iso_639_code_to_name_common(args,parts[4][1],parts[4][2]);-- suppress second return valuereturnretval;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 frame or an error message]]localfunctioniso_639_code_5_to_name(frame)localargs=getArgs(frame);localretval=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 valuereturnretval;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]]localfunctionname_in_part_code_get(name,part,part_idx,name_data)returnname_data[name]and(name_data[name][part_idx+5]or-- see if the name exists in the part's override tablename_data[name][part_idx]or-- see if the name exists in the part's main tablename_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 codeoverride data are examined first<args> is frame arguments from getArgs(frame)]]localfunction_iso_639_name_to_code(args)localhide='yes'==args['hide-err'];-- suppress error messages and error categorizationlocalnocat='no'==args.cat;-- suppress error categorization (primarily for demo use)ifnotargs[1]thenreturnerror_msg('name','',hide,nocat);-- abandon when language name missingendlocalname=args[1];-- used in error messaginglocallc_name=name:gsub(' +',' '):lower();-- lowercase version of name for indexing into the data table; strip extraneous space characterslocalpart_idx;localpart=args[2];ifpartthenpart_idx=get_part_index(part);ifnotpart_idxthenreturnerror_msg('not_part',part,hide,nocat);-- abandon; args[2] is not a valid ISO 639 partendendlocalname_data=mw.loadData('Module:ISO 639 name/ISO 639 name to code');-- ISO 639 language names to code tablelocalcode;ifpartthencode=name_in_part_code_get(lc_name,part,part_idx,name_data);-- search the specified override table + part tableelseforpart_idx,part_taginipairs({'1','2','2B','3','5'})do-- no part provided, spin through all parts override first and get the first available codecode=name_in_part_code_get(lc_name,part_tag,part_idx,name_data);ifcodethen-- nil when specified <part> does not have code for specified language <name>break;-- when code is not nil, doneendendendifcodethenreturncode,true;endreturnerror_msg('not_found',{name,partor'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 codeoverride data are examined firstargs[1] is language nameargs[2] is ISO 639 part]]localfunctioniso_639_name_to_code(frame)localargs=getArgs(frame);localresult,_=_iso_639_name_to_code(args);-- suppress true/false return used by iso_639_name_exists()returnresult;end--[[--------------------------< I S O _ 6 3 9 _ N A M E _ E X I S T S >----------------------------------------template entry point; returns ISO 639-1, -2, -3, or -5 code associated with language name according to part (1, 2, 3, 5) argument;when part is not provided scans 1, 2, 3 , 5 and returns first codeoverride data are examined firstargs[1] is language nameargs[2] is ISO 639 part]]localfunctioniso_639_name_exists(frame)localargs=getArgs(frame);local_,result=_iso_639_name_to_code(args);-- suppress code return used by iso_639_name_to_code()returnresultandtrueornil;end--[[--------------------------< I S O _ 6 3 9 >----------------------------------------------------------------template entry point.returns: language name if args[1] is valid language code language code if args[1] is valid language namethis function is constrained to the ISO 639 part specified in args[2] which must be 1, 2, 2B, 3, or 5. When not providedall parts are tested. The first match is found]]localfunctioniso_639(frame)localargs=getArgs(frame);localhide='yes'==args['hide-err'];-- suppress error messages and error categorizationlocalnocat='no'==args.cat;-- suppress error categorization (primarily for demo use)localresult;localfound;-- set to true when language name is foundifnotargs[1]thenreturnerror_msg('code_name','',hide,nocat);endlocalpart=args[2];ifpartthen-- if ISO 639 part suppliedlocalpart_idx=get_part_index(part);-- map index from <part>; anything else nilifnotpart_idxthenreturnerror_msg('not_part',part,hide,nocat);-- abandon; args[2] is not a valid ISO 639 partendresult,found=iso_639_code_to_name_common(args,parts[part_idx][1],parts[part_idx][2]);-- attempt to find a code matchiffoundthenreturnresult;-- found the code so return the language nameendresult=_iso_639_name_to_code(args);-- might be a language name; return code if it is; error message or empty string elsereturnresult;-- this way to suppress second returnelsefor_,partinipairs(parts)do-- for each of the iso 639 partsresult,found=iso_639_code_to_name_common(args,part[1],part[2]);-- attempt to find a code matchiffoundthenreturnresult;-- found the code so return the language nameendendendresult=_iso_639_name_to_code(args);-- might be a language name; return code if it is; error message or empty string elsereturnresult;-- this way to suppress second returnend--[[--------------------------< E X P O R T E D F U N C T I O N S >------------------------------------------]]return{iso_639=iso_639,-- returns code when given name; returns name when given codeiso_639_code_exists=iso_639_code_exists,iso_639_name_exists=iso_639_name_exists,iso_639_code_to_name=iso_639_code_to_name,iso_639_code_1_to_name=iso_639_code_1_to_name,iso_639_code_2_to_name=iso_639_code_2_to_name,iso_639_code_2B_to_name=iso_639_code_2B_to_name,iso_639_code_3_to_name=iso_639_code_3_to_name,iso_639_code_5_to_name=iso_639_code_5_to_name,iso_639_name_to_code=iso_639_name_to_code,};