Module:ISO 639
local p = {}
 local getArgs = require('Module:Arguments').getArgs
 local yesno = require('Module:Yesno')
 local data = mw.loadData('Module:ISO 639/data')
 local altnames = mw.loadData('Module:ISO 639/data/altnames') 
 local ISO_639_5 = mw.loadData('Module:ISO 639/data/ISO_639-5')
 
 function p.part2(frame)                                                         -- to output part 3 code
 	frame.args.type = &quot;part2&quot;
 	return p.main(frame)
 end
 
 function p.part5(frame)                                                         -- to output part 3 code
 	if yesno(frame.args.hierachy)  then
 		frame.args.type = &quot;hierachy&quot;
 	else
 		frame.args.type = &quot;part5&quot;
 	end
 	return p.main(frame)
 end
 
 function p.part3(frame)                                                         -- to output part 3 code
 	frame.args.type = &quot;part3&quot;
 	return p.main(frame)
 end
 
 function p.part1(frame)                                                         -- to output part 1 code
 	frame.args.type = &quot;part1&quot;
 	return p.main(frame)
 end
 
 function p.name(frame)                                                          -- to output name
 	frame.args.type = &quot;name&quot;
 	return p.main(frame)
 end
 
 function p.get(text)                                                            -- remove junk and standardizes
 	if text == table then
 		text = text[1]
 	end
 	if string.upper(text) == text then                                          -- assume it's a code when the input is all uppercase
 		text = string.lower(text)
 	end
 	local accents = {[&quot;À&quot;]=&quot;A&quot;,[&quot;Á&quot;]=&quot;A&quot;,[&quot;Â&quot;]=&quot;A&quot;,[&quot;Ã&quot;]=&quot;A&quot;,                   -- accent list
 		[&quot;Ä&quot;]=&quot;A&quot;,[&quot;Å&quot;]=&quot;A&quot;,[&quot;Ç&quot;]=&quot;C&quot;,[&quot;È&quot;]=&quot;E&quot;,[&quot;É&quot;]=&quot;E&quot;,
 		[&quot;Ê&quot;]=&quot;E&quot;,[&quot;Ë&quot;]=&quot;E&quot;,[&quot;Ì&quot;]=&quot;I&quot;,[&quot;Í&quot;]=&quot;I&quot;,[&quot;Î&quot;]=&quot;I&quot;,
 		[&quot;Ï&quot;]=&quot;I&quot;,[&quot;Ñ&quot;]=&quot;N&quot;,[&quot;Ò&quot;]=&quot;O&quot;,[&quot;Ó&quot;]=&quot;O&quot;,[&quot;Ô&quot;]=&quot;O&quot;,
 		[&quot;Õ&quot;]=&quot;O&quot;,[&quot;Ö&quot;]=&quot;O&quot;,[&quot;Ø&quot;]=&quot;O&quot;,[&quot;Ù&quot;]=&quot;U&quot;,[&quot;Ú&quot;]=&quot;U&quot;,
 		[&quot;Û&quot;]=&quot;U&quot;,[&quot;Ü&quot;]=&quot;U&quot;,[&quot;Ý&quot;]=&quot;Y&quot;
 	}
 		
 	text = mw.ustring.gsub(text,&quot;[À-Ý]&quot;,accents)                                -- Deaccent
 	text = mw.ustring.gsub(text,&quot;%[&quot;,&quot;&quot;)                                        -- Delink
 	text = mw.ustring.gsub(text,&quot;%]&quot;,&quot;&quot;)                                        -- Delink
 	text = mw.ustring.gsub(text,&quot;%{&quot;,&quot;&quot;)                                        -- Remove {
 	text = mw.ustring.gsub(text,&quot;%}&quot;,&quot;&quot;)                                        -- Remove }
 	return text 
 end
 
 function p.main(frame)                                                          -- main function (doesn't need to be called directly)
 	local args = getArgs(frame)
 	args[1] = p.get(args[1])                                                    
 
 	if altnames[args[1]] then args[1] = altnames[args[1]] end                   -- change alternate name to ISO 639-3 code
 	
 	if not args[1] then
 		return '&lt;span class=&quot;error&quot;&gt;Argument 1 is not set!&lt;/span&gt;'
 	end
 	
 	for part3,table in pairs(data) do
 		if args[1] == part3
 			or args[1] == table[&quot;part1&quot;]
 			or args[1] == table[&quot;part2&quot;]
 			or args[1] == table[&quot;name&quot;]
 		then
 			if args.type == &quot;part3&quot; then
 				return part3 or &quot;&quot;
 			elseif args.type == &quot;part1&quot; then
 				return table[&quot;part1&quot;] or &quot;&quot;
 			elseif args.type == &quot;part2&quot; then
 				return table[&quot;part2&quot;] or &quot;&quot;
 			elseif args.type == &quot;name&quot; then
 				return table[&quot;name&quot;] or &quot;&quot;
 			end
 		end
 	end
 	
 	for hierachy,table in pairs(ISO_639_5) do
 		if table.altnames then
 			for _,value in pairs(table.altnames) do
 				if args[1] == table then
 					args[1] = table.name
 				end
 			end
 		end
 		
 		if table[args[1]] == hierachy
 			or args[1] == table[&quot;part5&quot;]
 			or args[1] == table[&quot;part2&quot;]
 			or args[1] == table[&quot;name&quot;]
 		then
 			if args.type == &quot;hierachy&quot; then
 				return hierachy or &quot;&quot;
 			elseif args.type == &quot;part5&quot; then
 				return table[&quot;part5&quot;] or &quot;&quot;
 			elseif args.type == &quot;part2&quot; then
 				return table[&quot;part2&quot;] or &quot;&quot;
 			elseif args.type == &quot;name&quot; then
 				return table[&quot;name&quot;] or &quot;&quot;
 			end
 		end
 	end
 end