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

require('Module:No globals');

--[[--&#x3c; I S O _ 5 _ N A M E _ E X T R A C T &#x3e;--

reads a local copy of data from the table at https://www.loc.gov/standards/iso639-5/id.php, extracts the ISO 639-5 codes and their associated language names

useful lines in the source table have the form: &#x3c;Identifier&#x3e;\t&#x3c;English name&#x3e;\t&#x3c;French name&#x3e;\t&#x3c;639-2&#x3e;\t&#x3c;Hierarchy&#x3e;\t&#x3c;Notes&#x3e;\n where: &#x3c;Identifier&#x3e; is the 639-5 language code &#x3c;English name&#x3e; is the English name &#x3c;French names&#x3e; is the French name (not used here) &#x3c;639-2&#x3e; is language group or remainder group or blank (not used here) &#x3c;Hierarchy&#x3e; (not used here) &#x3c;Notes&#x3e; (not used here)

for the file date use the date listed at the bottom of the source page in yyyymmdd numeric format without hyphens or spaces

]]

local function ISO_5_name_extract (frame) local page = mw.title.getCurrentTitle;									-- get a page object for this page local content = page:getContent;											-- get unparsed content local content_table = {};													-- table of text lines from source local out_table = {};														-- output table local code, name;

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

content_table = mw.text.split (content, '[\r\n]');							-- make a table of text lines for _, line in ipairs (content_table) do									-- for each line code, name = line:match ('^(%l%l%l)\t([%a %-,%(%)\226\128\145]+)\t');	-- \226\128\145 is non-breaking hyphen U+2011 (E2 80 91) if code then name = name:gsub ('\226\128\145', '-');								-- replace non-breaking hyphens with hyphen-minus table.insert (out_table,				table.concat ({ '["',														-- open code index					code,					'"] = {"',													-- close code index; open name table					name,					'"}'														-- close the names table })			)		end end

table.sort (out_table); return "&#x3c;br /&#x3e;&#x3c;pre&#x3e;-- " .. file_date .. "&#x3c;br /&#x3e;return {&#x3c;br /&#x3e;&#x26;#9;" .. table.concat (out_table, ',&#x3c;br /&#x3e;&#x26;#9;') .. "&#x3c;br /&#x3e;&#x26;#9;}&#x3c;br /&#x3e;" .. "&#x3c;/pre&#x3e;"; end

----&

return { ISO_5_name_extract = ISO_5_name_extract };