Module:Lang/name to tag
local lang_data =  mw.loadData ('Module:Lang/data');							-- language name override and transliteration tool-tip tables
 local lang_name_table = lang_data.lang_name_table;								-- language codes, names, regions, scripts, suppressed scripts
 
 local lang_table = lang_name_table.lang;										-- language codes, names
 local lang_dep_table = lang_name_table.lang_dep;								-- deprecated language codes, names
 local override_table = lang_data.override;
 
 local rev_lang_table = {};														-- same as lang_table reversed so language name is key and language tag is value
 local rev_lang_dep_table = {};													-- same as lang_dep_table reversed so language name is key and language tag is value
 local rev_override_table = {};													-- same as override_table except reversed
 local dedabbed_names_list = {};													-- holds a list of dedabbed name and tags
 
 
 --[[--------------------------&lt; R E V _ L I S T _ A D D &gt;------------------------------------------------------
 
 local function to add &lt;name&gt; (key) and &lt;tag&gt; (value) pair to &lt;rev_list&gt;
 
 &lt;name&gt;/&lt;tag&gt; pairs where &lt;tag&gt; is ISO 639-1, overwrite all other &lt;name&gt;/&lt;tag&gt; pairs.  When creating overrides,
 take care that the &lt;name&gt; is properly disambiguated to avoid improper masking
 
 ]]
 
 local function rev_list_add (rev_list, name, tag)
 	if rev_list[name] then														-- if already in &lt;rev_list&gt;
 		if 2 == tag:len() then													-- is this is a 2-characater code?
 			rev_list[name] = tag;												-- yes, overwrite 3-characater language &lt;name&gt; and &lt;tag&gt; pair in &lt;rev_list&gt;
 		end
 	else																		-- here when not yet in &lt;rev_list&gt;
 		rev_list[name] = tag;													-- add language &lt;name&gt; and &lt;tag&gt; (value) pair to &lt;rev_list&gt;
 	end
 end
 
 
 --[[--------------------------&lt; D E D A B B E D _ N A M E S _ L I S T _ A D D &gt;--------------------------------
 
 adds &lt;name&gt;/&lt;tag&gt; pairs to the dedabbed_names_list when &lt;name&gt; not already present.  When &lt;name&gt; is present in
 the list, unsets the listed &lt;tag&gt; to empty string; cannot have different &lt;name&gt;/&lt;tag&gt; pairs where the table
 key (&lt;name&gt;) is shared with another &lt;name&gt;/&lt;tag&gt; pair.
 
 ]]
 
 local function dedabbed_names_list_add (dab, name, tag)
 	if 0 ~= dab then															-- if dab was removed
 		if dedabbed_names_list[name] then										-- if this dedabbed name is in the table then there are more than one name with different dabs
 			dedabbed_names_list[name] = '';										-- unset but not too unset
 		else
 			dedabbed_names_list[name] = tag;									-- add name / tag pair in case this the only dedabbed name
 		end
 	end
 end
 
 
 --[[--------------------------&lt; D E D A B B E D _ T O _ R E V _ L I S T _ A D D &gt;------------------------------
 
 adds &lt;name&gt;/&lt;tag&gt; pairs to specified &lt;rev_list&gt; when &lt;tag&gt; is not empty string
 
 ]]
 
 local function dedabbed_to_rev_list_add (rev_list, name, tag)
 	for name, tag in pairs (dedabbed_names_list) do								-- add dedabbed &lt;name&gt;/&lt;tag&gt; pairs to the reversed table
 		if '' ~= tag then														-- when &lt;name&gt;/&lt;tag&gt; has not been unset because of multiple dabs
 			rev_list_add (rev_list, name, tag);									-- add
 		end
 	end
 end
 
 
 --[[--------------------------&lt; T A G - F R O M - N A M E   D A T A &gt;------------------------------------------
 
 Creates tag-from-name tables from the data in Module:Lang/data so that templates can get language tags from the
 same names as the {{lang}} templates get from those tags.  The conversion prefers ISO 639-1 codes.
 
 Data in these tables are used by tag_from_name() in Module:Lang
 
 When &lt;name&gt; is disambiguated, will create an additional &lt;name&gt; entry without the dab as long as that action won't
 conflict with actual undabbed names in the source.
 
 &lt;name&gt; without dab is always added to the list; this rule arises because of the three Marwari language code/name pairs:
 	mwr: Marwari																-– not dabbed
 these will not have dedabbed entries because of mwr
 	rwr: Marwari (India)
 	mve: Marwari (Pakistan)
 
 These all share the same base name so there will not not be an dedabbed entry:
 	[&quot;yaka&quot;] = &quot;axk&quot;,															-- this would be wrong for two of these languages
 	[&quot;yaka (central african republic)&quot;] = &quot;axk&quot;,
 	[&quot;yaka (congo)&quot;] = &quot;iyx&quot;,
 	[&quot;yaka (democratic republic of congo)&quot;] = &quot;yaf&quot;,
 
 Say that we find &quot;axk&quot;.  It has a dab so we add the dabbed form to rev_lang_table{}.  Then we look in
 dedabbed_names_list{} to see if [&quot;yaka&quot;] is already there.  It's not, so we add this:
 	[&quot;yaka&quot;] = &quot;axk&quot;,
 Later we find &quot;yaf&quot;.  It has a dab so we add the dabbed form to rev_lang_table{}.  Then we look in
 dedabbed_names_list{} to see if [&quot;yaka&quot;] is already there.  It is, so that means that more than one language
 code could create an dedabbed language name key; there can be only one.  Because [&quot;yaka&quot;] is already in the
 dedabbed_names_list{} table we unset the [&quot;yaka&quot;] entry to empty string:
 	[&quot;yaka&quot;] = '',
 later we find &quot;iyx&quot; and add it to rev_lang_table{}.  We look in dedabbed_names_list{} and find [&quot;yaka&quot;] has been
 unset to empty string so do nothing.
 
 When done adding names/codes to rev_lang_table{}, spin through dedabbed_names_list{} and add all non-empty-string
 name/code pairs to rev_lang_table{}.
 
 This does not catch things like overrides [&quot;pa&quot;] = &quot;Punjabi&quot; and [&quot;pnb&quot;] = &quot;Punjabi&quot;.  &quot;pa&quot; and &quot;pnb&quot; are not
 synonyms but because the names are the same, will be treated like synonyms (&quot;pnb&quot; promotes to &quot;pa&quot;). To avoid
 this, disambiguate the override: [&quot;pnb&quot;] = {&quot;Punjabi&quot;} -&gt; [&quot;pnb&quot;] = {&quot;Punjabi (Western)&quot;}
 
 ]]
 
 for tag, name_table in pairs (lang_table) do
 	if not override_table[tag] then												-- only add names/tags from name_table when tag not present in override table
 		local name_raw = name_table:lower();
 		local name, dab = name_raw:gsub ('%s+%b()', '');						-- remove parenthetical disambiguators or qualifiers from names that have them; &lt;dab&gt; non-zero when disambiguation removed
 	
 		rev_list_add (rev_lang_table, name_raw, tag);							-- add no-dab-names and names-with-dab here
 		dedabbed_names_list_add (dab, name, tag);								-- add to dedabbed_names_list if dabbed
 	end
 end
 
 dedabbed_to_rev_list_add (rev_lang_table, name, tag);							-- add dedabbed name/tag pairs to the reversed table
 
 dedabbed_names_list = {};														-- reset list of dedabbed names
 
 for tag, name_table in pairs (lang_dep_table) do
 	if not override_table[tag] then												-- only add names/tags from name_table when tag not present in override table
 		local name_raw = name_table:lower();
 		local name, dab = name_raw:gsub ('%s+%b()', '');						-- remove parenthetical disambiguators or qualifiers from names that have them; &lt;dab&gt; non-zero when disambiguation removed
 	
 		rev_list_add (rev_lang_dep_table, name_raw, tag);						-- add no-dab-names and names-with-dab here
 		dedabbed_names_list_add (dab, name, tag);								-- add to dedabbed_names_list if dabbed
 	end
 end
 
 dedabbed_to_rev_list_add (rev_lang_dep_table, name, tag);						-- add dedabbed name/tag pairs to the reversed table
 
 dedabbed_names_list = {};														-- reset list of dedabbed names
 
 for tag, name_table in pairs (override_table) do
 	local name_raw = name_table:lower();
 	local name, dab = name_raw:gsub ('%s+%b()', '');							-- remove parenthetical disambiguators or qualifiers from names that have them
 
 	rev_list_add (rev_override_table, name_raw, tag);
 	dedabbed_names_list_add (dab, name, tag);									-- add to dedabbed_names_list if dabbed
 end
 
 dedabbed_to_rev_list_add (rev_override_table, name, tag);						-- add dedabbed name/tag pairs to the reversed table
 
 dedabbed_names_list = {};														-- reset list
 
 
 --[[--------------------------&lt; E X P O R T E D   T A B L E S &gt;------------------------------------------------
 ]]
 
 return {
 	rev_lang_table = rev_lang_table,
 	rev_lang_dep_table = rev_lang_dep_table,
 	rev_override_table = rev_override_table,