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

require('Module:No globals'); local p = {};

--[=[&#x3c; I S O _ 6 3 9 _ 3 _ E X T R A C T &#x3e;-

Reads a local copy of iso-639-3_Name_Index_YYYYMMDD.tab where (YYYYMMDD is the release date). Download that file in zip form from http://www-01.sil.org/iso639-3/download.asp (use the UTF-8 zip)

useful lines in the file have the form: &#x3c;id&#x3e;\t&#x3c;name&#x3e;\t&#x3c;inverted name&#x3e;\n where: &#x3c;id&#x3e; is the three-character ISO 639-3 language code &#x3c;name&#x3e; is the language 'name' &#x3c;inverted name&#x3e; is the language in 'last-name, first-name(s)' form; this part ignored like this: aaq	Eastern Abnaki	Abnaki, Eastern

when a language code has more than one name, the code is repeated for each additional name: rar	Cook Islands Maori	Maori, Cook Islands rar	Rarotongan	Rarotongan

]=]

function p.ISO_639_3_extract (frame) local page = mw.title.getCurrentTitle;									-- get a page object for this page local content = page:getContent;											-- get unparsed content local lang_table = {};														-- languages go here

local code; local names;

local file_date = 'File-Date: ' .. frame.args["file-date"];									-- set the file date line from |file-date=

for code, name in mw.ustring.gmatch (content, '%f[%a](%a%a%a)\t([^\t]+)\t[^\n]+\n') do		-- get code and 'forward' name if code then if string.find (lang_table[#lang_table] or , '^%[\"' .. code) then				-- if this is an additional name for code ('or' empty string for first time when lang_table[#lang_table] is nil)				lang_table[#lang_table] = mw.ustring.gsub (lang_table[#lang_table], '}$', );	-- remove trailing brace from previous name				lang_table[#lang_table] = lang_table[#lang_table] .. ', \"' .. name .. '\"}';	-- add this name with new brace 			else				table.insert (lang_table, "[\"" .. code .. "\"] = {\"" .. name .. "\"}");		-- make new table entry			end		elseif not code then			table.insert (lang_table, "[\"error\"] = {" .. record .. "}");						-- code should never be nil, but inserting an error entry in the final output can be helpful		end	end																				-- make pretty output	return "&#x3c;br /&#x3e;&#x3c;pre&#x3e;-- " .. file_date .. "&#x3c;br /&#x3e;return {&#x3c;br /&#x3e;&#x26;#9;" .. table.concat (lang_table, ',&#x3c;br /&#x3e;&#x26;#9;') .. "&#x3c;br /&#x3e;&#x26;#9;}&#x3c;br /&#x3e;" .. "&#x3c;/pre&#x3e;"; end

return p;