Module:Codenat

Lua

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

The module gets a 3-byte ISO language code and returns the corresponding full English name of the nation.

The data, more than 200 code → nation items, is taken from Template:{{Olympic teams}}.

Invocation example: {{#invoke:Codenat|codnat|GER}} will return "Germany".

When necessary, the table can easily be expanded that it serves not only the ISO 639-2/B codes but also the ISO 639-2/T, e.g.

Flag icon templates will need an article for all plural forms, as e.g.

But it can be used also for nation names as e.g.

and it is not the same in all languages!

Code

local p = {}

function p.codnat ( frame )
	local args = frame.args
	local nnm  = mw.text.trim ( args[1] or '' );	
	local ncd  = mw.ustring.upper( nnm )
	if ncd ~= '' then
		if 		ncd == 'AFG'  then  nnm = 'Afghanistan';
		elseif	ncd == 'ALB'  then  nnm = 'Albania';
		elseif	ncd == 'ALG'  then  nnm = 'Algeria';
		elseif	ncd == 'AND'  then  nnm = 'Andorra';
		elseif	ncd == 'ANG'  then  nnm = 'Angola';
		elseif	ncd == 'ANT'  then  nnm = 'Antigua and Barbuda';
		elseif	ncd == 'ARG'  then  nnm = 'Argentina';
		elseif	ncd == 'ARM'  then  nnm = 'Armenia';
		elseif	ncd == 'ARU'  then  nnm = 'Aruba';
		elseif	ncd == 'ASA'  then  nnm = 'American Samoa';
		elseif	ncd == 'AUS'  then  nnm = 'Australia';
		elseif	ncd == 'AUT'  then  nnm = 'Austria';
		elseif	ncd == 'AZE'  then  nnm = 'Azerbaijan';
		elseif	ncd == 'BAH'  then  nnm = 'Bahamas';
		elseif	ncd == 'BAN'  then  nnm = 'Bangladesh';
		elseif	ncd == 'BAR'  then  nnm = 'Barbados';
		elseif	ncd == 'BDI'  then  nnm = 'Burundi';
		elseif	ncd == 'BEL'  then  nnm = 'Belgium';
		elseif	ncd == 'BEN'  then  nnm = 'Benin';
		elseif	ncd == 'BER'  then  nnm = 'Bermuda';
		elseif	ncd == 'BHU'  then  nnm = 'Bhutan';
		elseif	ncd == 'BIH'  then  nnm = 'Bosnia and Herzegovina';
		elseif	ncd == 'BIZ'  then  nnm = 'Belize';
		elseif	ncd == 'BLR'  then  nnm = 'Belarus';
		elseif	ncd == 'BOL'  then  nnm = 'Bolivia';
		elseif	ncd == 'BOT'  then  nnm = 'Botswana';
		elseif	ncd == 'BRA'  then  nnm = 'Brazil';
		elseif	ncd == 'BRN'  then  nnm = 'Bahrain';
		elseif	ncd == 'BRU'  then  nnm = 'Brunei';
		elseif	ncd == 'BUL'  then  nnm = 'Bulgaria';
		elseif	ncd == 'BUR'  then  nnm = 'Burkina Faso';
		elseif	ncd == 'CAF'  then  nnm = 'Central African Republic';
		elseif	ncd == 'CAM'  then  nnm = 'Cambodia';
		elseif	ncd == 'CAN'  then  nnm = 'Canada';
		elseif	ncd == 'CAY'  then  nnm = 'Cayman Islands';
		elseif	ncd == 'CGO'  then  nnm = 'Congo-Brazzaville';
		elseif	ncd == 'CHA'  then  nnm = 'Chad';
		elseif	ncd == 'CHI'  then  nnm = 'Chile';
		elseif	ncd == 'CHN'  then  nnm = "China";
		elseif	ncd == 'CIV'  then  nnm = "Côte d'Ivoire";
		elseif	ncd == 'CMR'  then  nnm = 'Cameroon';
		elseif	ncd == 'COD'  then  nnm = 'Congo-Kinshasa';
		elseif	ncd == 'COK'  then  nnm = 'Cook Islands';
		elseif	ncd == 'COL'  then  nnm = 'Colombia';
		elseif	ncd == 'COM'  then  nnm = 'Comoros';
		elseif	ncd == 'CPV'  then  nnm = 'Cape Verde';
		elseif	ncd == 'CRC'  then  nnm = 'Costa Rica';
		elseif	ncd == 'CRO'  then  nnm = 'Croatia';
		elseif	ncd == 'CUB'  then  nnm = 'Cuba';
		elseif	ncd == 'CYP'  then  nnm = 'Cyprus';
		elseif	ncd == 'CZE'  then  nnm = 'Czechia';
		elseif	ncd == 'DEN'  then  nnm = 'Denmark';
		elseif	ncd == 'DJI'  then  nnm = 'Djibouti';
		elseif	ncd == 'DMA'  then  nnm = 'Dominica';
		elseif	ncd == 'DOM'  then  nnm = 'Dominican Republic';
		elseif	ncd == 'ECU'  then  nnm = 'Ecuador';
		elseif	ncd == 'EGY'  then  nnm = 'Egypt';
		elseif	ncd == 'ERI'  then  nnm = 'Eritrea';
		elseif	ncd == 'ESA'  then  nnm = 'El Salvador';
		elseif	ncd == 'ESP'  then  nnm = 'Spain';
		elseif	ncd == 'EST'  then  nnm = 'Estonia';
		elseif	ncd == 'ETH'  then  nnm = 'Ethiopia';
		elseif	ncd == 'FIJ'  then  nnm = 'Fiji';
		elseif	ncd == 'FIN'  then  nnm = 'Finland';
		elseif	ncd == 'FRA'  then  nnm = 'France';
		elseif	ncd == 'FRO'  then  nnm = 'Faroe Islands';
		elseif	ncd == 'FSM'  then  nnm = 'Micronesia';
		elseif	ncd == 'GAB'  then  nnm = 'Gabon';
		elseif	ncd == 'GAM'  then  nnm = 'Gambia';
		elseif	ncd == 'GBR'  then  nnm = 'United Kingdom';
		elseif	ncd == 'GBS'  then  nnm = 'Guinea-Bissau';
		elseif	ncd == 'GEO'  then  nnm = 'Georgia';
		elseif	ncd == 'GEQ'  then  nnm = 'Equatorial Guinea';
		elseif	ncd == 'GER'  then  nnm = 'Germany';
		elseif	ncd == 'GHA'  then  nnm = 'Ghana';
		elseif	ncd == 'GRC'  then  nnm = 'Greece';
		elseif	ncd == 'GRN'  then  nnm = 'Grenada';
		elseif	ncd == 'GUA'  then  nnm = 'Guatemala';
		elseif	ncd == 'GUI'  then  nnm = 'Guinea';
		elseif	ncd == 'GUM'  then  nnm = 'Guam';
		elseif	ncd == 'GUY'  then  nnm = 'Guyana';
		elseif	ncd == 'HAI'  then  nnm = 'Haiti';
		elseif	ncd == 'HKG'  then  nnm = 'Hong Kong';
		elseif	ncd == 'HON'  then  nnm = 'Honduras';
		elseif	ncd == 'HUN'  then  nnm = 'Hungary';
		elseif	ncd == 'IDN'  then  nnm = 'Indonesia';
		elseif	ncd == 'IND'  then  nnm = 'India';
		elseif	ncd == 'IRI'  then  nnm = 'Iran';
		elseif	ncd == 'IRL'  then  nnm = 'Ireland';
		elseif	ncd == 'IRQ'  then  nnm = 'Iraq';
		elseif	ncd == 'ISL'  then  nnm = 'Iceland';
		elseif	ncd == 'ISR'  then  nnm = 'Israel';
		elseif	ncd == 'ISV'  then  nnm = 'United States Virgin Islands';
		elseif	ncd == 'ITA'  then  nnm = 'Italy';
		elseif	ncd == 'IVB'  then  nnm = 'British Virgin Islands';
		elseif	ncd == 'JAM'  then  nnm = 'Jamaica';
		elseif	ncd == 'JOR'  then  nnm = 'Jordan';
		elseif	ncd == 'JPN'  then  nnm = 'Japan';
		elseif	ncd == 'KAZ'  then  nnm = 'Kazakhstan';
		elseif	ncd == 'KEN'  then  nnm = 'Kenya';
		elseif	ncd == 'KGZ'  then  nnm = 'Kyrgyzstan';
		elseif	ncd == 'KIR'  then  nnm = 'Kiribati';
		elseif	ncd == 'KOR'  then  nnm = 'South Korea';
		elseif	ncd == 'KOS'  then  nnm = 'Kosovo';
		elseif	ncd == 'KSA'  then  nnm = 'Saudi Arabia';
		elseif	ncd == 'KUW'  then  nnm = 'Kuwait';
		elseif	ncd == 'LAO'  then  nnm = 'Laos';
		elseif	ncd == 'LAT'  then  nnm = 'Latvia';
		elseif	ncd == 'LBA'  then  nnm = 'Libya';
		elseif	ncd == 'LBN'  then  nnm = 'Lebanon';
		elseif	ncd == 'LBR'  then  nnm = 'Liberia';
		elseif	ncd == 'LCA'  then  nnm = 'Saint Lucia';
		elseif	ncd == 'LES'  then  nnm = 'Lesotho';
		elseif	ncd == 'LIE'  then  nnm = 'Liechtenstein';
		elseif	ncd == 'LTU'  then  nnm = 'Lithuania';
		elseif	ncd == 'LUX'  then  nnm = 'Luxembourg';
		elseif	ncd == 'MAC'  then  nnm = 'Macau';
		elseif	ncd == 'MAD'  then  nnm = 'Madagascar';
		elseif	ncd == 'MAR'  then  nnm = 'Morocco';
		elseif	ncd == 'MAS'  then  nnm = 'Malaysia';
		elseif	ncd == 'MAW'  then  nnm = 'Malawi';
		elseif	ncd == 'MDA'  then  nnm = 'Moldova';
		elseif	ncd == 'MDV'  then  nnm = 'Maldives';
		elseif	ncd == 'MEX'  then  nnm = 'Mexico';
		elseif	ncd == 'MGL'  then  nnm = 'Mongolia';
		elseif	ncd == 'MHL'  then  nnm = 'Marshall Islands';
		elseif	ncd == 'MKD'  then  nnm = 'North Macedonia';
		elseif	ncd == 'MLI'  then  nnm = 'Mali';
		elseif	ncd == 'MLT'  then  nnm = 'Malta';
		elseif	ncd == 'MNE'  then  nnm = 'Montenegro';
		elseif	ncd == 'MON'  then  nnm = 'Monaco';
		elseif	ncd == 'MOZ'  then  nnm = 'Mozambique';
		elseif	ncd == 'MRI'  then  nnm = 'Mauritius';
		elseif	ncd == 'MTN'  then  nnm = 'Mauritania';
		elseif	ncd == 'MYA'  then  nnm = 'Myanmar';
		elseif	ncd == 'NAM'  then  nnm = 'Namibia';
		elseif	ncd == 'NCA'  then  nnm = 'Nicaragua';
		elseif	ncd == 'NLD'  then  nnm = 'Netherlands';
		elseif	ncd == 'NEP'  then  nnm = 'Nepal';
		elseif	ncd == 'NGR'  then  nnm = 'Nigeria';
		elseif	ncd == 'NIG'  then  nnm = 'Niger';
		elseif	ncd == 'NOR'  then  nnm = 'Norway';
		elseif	ncd == 'NRU'  then  nnm = 'Nauru';
		elseif	ncd == 'NZL'  then  nnm = 'New Zealand';
		elseif	ncd == 'OMA'  then  nnm = 'Oman';
		elseif	ncd == 'PAK'  then  nnm = 'Pakistan';
		elseif	ncd == 'PAN'  then  nnm = 'Panama';
		elseif	ncd == 'PAR'  then  nnm = 'Paraguay';
		elseif	ncd == 'PER'  then  nnm = 'Peru';
		elseif	ncd == 'PHL'  then  nnm = 'Philippines';
		elseif	ncd == 'PLE'  then  nnm = 'Palestine';
		elseif	ncd == 'PLW'  then  nnm = 'Palau';
		elseif	ncd == 'PNG'  then  nnm = 'Papua New Guinea';
		elseif	ncd == 'POL'  then  nnm = 'Poland';
		elseif	ncd == 'POR'  then  nnm = 'Portugal';
		elseif	ncd == 'PRK'  then  nnm = 'North Korea';
		elseif	ncd == 'PUR'  then  nnm = 'Puerto Rico';
		elseif	ncd == 'QAT'  then  nnm = 'Qatar';
		elseif	ncd == 'ROU'  then  nnm = 'Romania';
		elseif	ncd == 'ZAF'  then  nnm = 'South Africa';
		elseif	ncd == 'RUS'  then  nnm = 'Russia';
		elseif	ncd == 'RWA'  then  nnm = 'Rwanda';
		elseif	ncd == 'SAM'  then  nnm = 'Samoa';
		elseif	ncd == 'SEN'  then  nnm = 'Senegal';
		elseif	ncd == 'SEY'  then  nnm = 'Seychelles';
		elseif	ncd == 'SGP'  then  nnm = 'Singapore';
		elseif	ncd == 'SKN'  then  nnm = 'Saint Kitts and Nevis';
		elseif	ncd == 'SLE'  then  nnm = 'Sierra Leone';
		elseif	ncd == 'SLO'  then  nnm = 'Slovenia';
		elseif	ncd == 'SMR'  then  nnm = 'San Marino';
		elseif	ncd == 'SOL'  then  nnm = 'Solomon Islands';
		elseif	ncd == 'SOM'  then  nnm = 'Somalia';
		elseif	ncd == 'SRB'  then  nnm = 'Serbia';
		elseif	ncd == 'SRI'  then  nnm = 'Sri Lanka';
		elseif	ncd == 'SSD'  then  nnm = 'South Sudan';
		elseif	ncd == 'STP'  then  nnm = 'São Tomé and Príncipe';
		elseif	ncd == 'SUD'  then  nnm = 'Sudan';
		elseif	ncd == 'SUI'  then  nnm = 'Switzerland';
		elseif	ncd == 'SUR'  then  nnm = 'Suriname';
		elseif	ncd == 'SVK'  then  nnm = 'Slovakia';
		elseif	ncd == 'SWE'  then  nnm = 'Sweden';
		elseif	ncd == 'SWZ'  then  nnm = 'Eswatini';
		elseif	ncd == 'SYR'  then  nnm = 'Syria';
		elseif	ncd == 'TAN'  then  nnm = 'Tanzania';
		elseif	ncd == 'TGA'  then  nnm = 'Tonga';
		elseif	ncd == 'THA'  then  nnm = 'Thailand';
		elseif	ncd == 'TJK'  then  nnm = 'Tajikistan';
		elseif	ncd == 'TKM'  then  nnm = 'Turkmenistan';
		elseif	ncd == 'TLS'  then  nnm = 'East Timor';
		elseif	ncd == 'TOG'  then  nnm = 'Togo';
		elseif	ncd == 'TPE'  then  nnm = 'Taiwan';
		elseif	ncd == 'TTO'  then  nnm = 'Trinidad and Tobago';
		elseif	ncd == 'TUN'  then  nnm = 'Tunisia';
		elseif	ncd == 'TUR'  then  nnm = 'Turkey';
		elseif	ncd == 'TUV'  then  nnm = 'Tuvalu';
		elseif	ncd == 'ARE'  then  nnm = 'United Arab Emirates';
		elseif	ncd == 'UGA'  then  nnm = 'Uganda';
		elseif	ncd == 'UKR'  then  nnm = 'Ukraine';
		elseif	ncd == 'URU'  then  nnm = 'Uruguay';
		elseif	ncd == 'USA'  then  nnm = 'United States';
		elseif	ncd == 'UZB'  then  nnm = 'Uzbekistan';
		elseif	ncd == 'VAN'  then  nnm = 'Vanuatu';
		elseif	ncd == 'VEN'  then  nnm = 'Venezuela';
		elseif	ncd == 'VIE'  then  nnm = 'Vietnam';
		elseif	ncd == 'VIN'  then  nnm = 'Saint Vincent and the Grenadines';
		elseif	ncd == 'YEM'  then  nnm = 'Yemen';
		elseif	ncd == 'ZAM'  then  nnm = 'Zambia';
		elseif	ncd == 'ZIM'  then  nnm = 'Zimbabwe';
		else    nnm  = 'wrong code';		-- not found: return [empty string?]
		end
	end
	return nnm;
end

function p.codplu ( frame )			-- article ("the") for plural forms of flag icons
	local args = frame.args
	local ret  = '';
	local ncd  = mw.ustring.upper( mw.text.trim ( args[1] ) ) or '';
	if ncd ~= '' then
		if	ncd == 'CAY'
		or	ncd == 'FRO'
		or	ncd == 'FSM'
		or	ncd == 'ISV'
		or	ncd == 'IVB'
		or	ncd == 'MHL'
		or	ncd == 'NLD'
		or	ncd == 'PHL'
		or	ncd == 'UAE'
		or	ncd == 'USA'
		then ret = '1'; 
		end
	end
	return ret;
end

return p;
Category:Modules for general use