local lang_obj = mw.language.getContentLanguage;
local this_wiki_lang_tag = lang_obj.code; -- get this wiki's language tag  
----------------------------< L A N G _ N A M E _ T A B L E >------------------------------------------------  
primary table of tables that decode:
lang -> language tags and names
script -> ISO 15924 script tags
region -> ISO 3166 region tags
variant -> iana registered variant tags
suppressed -> map of scripts tags and their associated language tags  
all of these data come from separate modules that are derived from the IANA language-subtag-registry file  
key_to_lower avoids the metatable trap and sets all keys in the subtables to lowercase. Many language codes
have multiple associated names; Module:lang is only concerned with the first name so key_to_lower only fetches
the first name.  
local function key_to_lower (module, src_type)
local out = {};
local source_t = (('var_sup' == src_type) and require (module)) or mw.loadData (module); -- fetch data from this module; require avoids metatable trap for variant data  
if 'var_sup' == src_type then
for k, v in pairs (source_t) do
out[k:lower] = v; -- for variant and suppressed everything is needed
end  
elseif 'lang' == src_type and source_t.active then -- for ~/iana_languages (active)
for k, v in pairs (source_t.active) do
out[k:lower] = v[1]; -- ignore multiple names; take first name only
end  
elseif 'lang_dep' == src_type and source_t.deprecated then -- for ~/iana_languages (deprecated)
for k, v in pairs (source_t.deprecated) do
out[k:lower] = v[1]; -- ignore multiple names; take first name only
end  
else -- here for all other sources
for k, v in pairs (source_t) do
out[k:lower] = v[1]; -- ignore multiple names; take first name only
end
end
return out;
end  
local lang_name_table_t = {
lang = key_to_lower ('Module:Lang/data/iana languages', 'lang'),
lang_dep = key_to_lower ('Module:Lang/data/iana languages', 'lang_dep'),
script = key_to_lower ('Module:Lang/data/iana scripts'), -- script keys are capitalized; set to lower
region = key_to_lower ('Module:Lang/data/iana regions'), -- region keys are uppercase; set to lower
variant = key_to_lower ('Module:Lang/data/iana variants', 'var_sup'),
suppressed = key_to_lower ('Module:Lang/data/iana suppressed scripts', 'var_sup'), -- script keys are capitalized; set to lower
}  
----------------------------< I 1 8 N M E D I A W I K I O V E R R I D E >--------------------------------  
For internationalization; not used at en.wiki  
The language names taken from the IANA language-subtag-registry file are given in English. That may not be ideal.
Translating ~8,000 language names is also not ideal. MediaWiki maintains (much) shorter lists of language names
in most languages for which there is a Wikipedia edition. When desired, Module:Lang can use the MediaWiki
language list for the local language.  
Caveat lector: the list of MediaWiki language names for your language may not be complete or may not exist at all.
When incomplete, MediaWiki's list will 'fall back' to another language (typically English). When that happens
add an appropriate entry to the override table below.  
Caveat lector: the list of MediaWiki language names for your language may not be correct. At en.wiki, the
MediaWiki language names do not agree with the IANA language names for these ISO 639-1 tags. Often it is simply
spelling differences:
bh: IANA: Bihari languages MW: Bhojpuri – the ISO 639-3 tag for Bhojpuri is bho
bn: IANA: Bengali MW: Bangla – Bengali is the exonym, Bangla is the endonym
dv: IANA: Dhivehi MW: Divehi
el: IANA: Modern Greek MW: Greek
ht: IANA: Haitian MW: Haitian Creole
ky: IANA: Kirghiz MW: Kyrgyz
li: IANA: Limburgan MW: Limburgish
or: IANA: Oriya MW: Odia
os: IANA: Ossetian MW: Ossetic
"pa: IANA: Panjabi MW: Punjabi
"ps: IANA: Pushto MW: Pashto
"to: IANA: Tonga MW: Tongan
"ug: IANA: Uighur MW: Uyghur
use the override table to override language names that are incorrect for your project  
To see the list of names that MediaWiki has for your language, enter this in the Debug colsole:
=mw.dumpObject (mw.language.fetchLanguageNames ('<tag>', 'all'))
(replacing <tag> with the language tag for your language)  
Use of the MediaWiki language names lists is enabled when media_wiki_override_enable is set to boolean true.  
local media_wiki_override_enable = false; -- set to true to override IANA names with MediaWiki names; always false at en.wiki
-- caveat lector: the list of MediaWiki language names for your language may not be complete or may not exist at all
if true == media_wiki_override_enable then
local mw_languages_by_tag_t = mw.language.fetchLanguageNames (this_wiki_lang_tag, 'all'); -- get a table of language tag/name pairs known to MediaWiki
for tag, name in pairs (mw_languages_by_tag_t) do -- loop through each tag/name pair in the MediaWiki list
if lang_name_table_t.lang[tag] then -- if the tag is in the main list
lang_name_table_t.lang[tag] = name; -- overwrite exisiting name with the name from MediaWiki
end
end
end  
----------------------------< O V E R R I D E >--------------------------------------------------------------  
Language codes and names in this table override the BCP47 names in lang_name_table.  
indexes in this table shall always be lower case  
local override = {
------------------------------< I S O _ 6 3 9 - 1 >------------------------------------------------------------  
["ab"] = "Abkhaz", -- to match en.wiki article name
["ca-valencia"] = "Valencian",
["cu"] = "Church Slavonic", -- 2nd IANA name;
["de-at"] = "Austrian German", -- these code-region and code-variant tags to match en.wiki article names
["de-ch"] = "Swiss Standard German",
["en-au"] = "Australian English",
["en-ca"] = "Canadian English",
["en-emodeng"] = "Early Modern English",
["en-gb"] = "British English",
["en-ie"] = "Irish English",
["en-in"] = "Indian English",
["en-nz"] = "New Zealand English",
["en-us"] = "American English",
["en-za"] = "South African English",
["fr-ca"] = "Quebec French",
["fr-gallo"] = "Gallo",
["fy"] = "West Frisian", -- Western Frisian
["mo"] = "Moldovan", -- Moldavian (deprecated code); to match en.wiki article title
["nl-be"] = "Flemish", -- match MediaWiki
["oc-gascon"] = "Gascon",
["oc-provenc"] = "Provençal",
["ps"] = "Pashto", -- Pushto
["pt-br"] = "Brazilian Portuguese", -- match MediaWiki
["ro-md"] = "Moldovan", -- 'not deprecated' form
["ro-cyrl-md"] = "Moldovan", -- 'not deprecated' form
["tw-asante"] = "Asante Twi",
["ug"] = "Uyghur", -- 2nd IANA name; to match en.wiki article name  
-- these ISO 639-1 language-name overrides imported from Module:Language/data/wp_languages (since deleted)
--<begin do-not-edit except to comment out>--
["av"] = "Avar", -- Avaric
["bo"] = "Standard Tibetan", -- Tibetan
["el"] = "Greek", -- Modern Greek
-- ["en-SA"] = "South African English", -- English; no; SA is not South Africa it Saudi Arabia; ZA is South Africa
["ff"] = "Fula", -- Fulah
["ht"] = "Haitian Creole", -- Haitian
["hz"] = "Otjiherero", -- Herero
["ii"] = "Yi", -- Sichuan Yi
["ki"] = "Gikuyu", -- Kikuyu
["kl"] = "Greenlandic", -- Kalaallisut
["ky"] = "Kyrgyz", -- Kirghiz
["lg"] = "Luganda", -- Ganda
["li"] = "Limburgish", -- Limburgan
["mi"] = "Māori", -- Maori
["na"] = "Nauruan", -- Nauru
["nb"] = "Bokmål", -- Norwegian Bokmål
["nd"] = "Northern Ndebele", -- North Ndebele
["nn"] = "Nynorsk", -- Norwegian Nynorsk
["nr"] = "Southern Ndebele", -- South Ndebele
["ny"] = "Chichewa", -- Nyanja
["oj"] = "Ojibwe", -- Ojibwa
["or"] = "Odia", -- Oriya
["pa"] = "Punjabi", -- Panjabi
["rn"] = "Kirundi", -- Rundi
["sl"] = "Slovene", -- Slovenian
["ss"] = "Swazi", -- Swati
["st"] = "Sotho", -- Southern Sotho
["to"] = "Tongan", -- Tonga
--<end do-not-edit except to comment out>--  
------------------------------< I S O _ 6 3 9 - 2, - 3, - 5 >----------------------------------------------  
["alv"] = "Atlantic–Congo languages", -- to match en.wiki article title (endash)