Module:Language/data/ISO 639-1/make

Documentation for this module may be created at Module:Language/data/ISO 639-1/make/doc

getArgs = require('Module:Arguments').getArgs


--[[--------------------------< I S O _ 1 _ N A M E _ E X T R A C T >------------------------------------------

{{#invoke:Language/data/ISO 639-1/make|extract|file-date=2020-07-17}}

 Reads Module:Language/data/iana languages and extract ISO 639-1 codes with their associated languge names.
 An alternate data source may be provided using positional parameter 1 (args[1] or {{{1}}})

]]

function extract (frame)
	local export = {}
	local args = getArgs(frame)
	local data = mw.loadData (args[1] or 'Module:Language/data/iana languages')

	local file_date = 'File-Date: ' .. (args["file-date"] or '');				-- set the file date line from |file-date= (from the top of the source page)

	for k, v in pairs (data) do
		if 2 == k:len() then
			local temp = {};
			for key, value in ipairs (v) do
				table.insert (temp, table.concat ({'\"', value, '\"'}))			-- quoted language name
			end
			table.insert (export, table.concat ({'["'..k..'"] = {',				-- index + table open
				table.concat (temp, ', '),										-- comma separated list of language names
				'}'																-- table close
				}))
		end
	end
	
	table.sort (export)															-- sort by language codes
	
	return "<br /><pre>-- " .. file_date .. "<br />return {<br />&#9;" .. table.concat (export, ',<br />&#9;') .. "<br />&#9;}<br />" .. "</pre>";
end


--[[--------------------------< E X P O R T E D   F U N C T I O N S >------------------------------------------
]]

return {
	extract = extract
	}