Jump to content

Module:ISO 639 name

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Trappist the monk (talk | contribs) at 22:20, 23 September 2018 (create;). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

require('Module:No globals');

local getArgs = require ('Module:Arguments').getArgs;
local part1_data = mw.loadData ('Module:Language/data/iana languages');			-- used only for ISO 639-1 language codes / names
local part2_data = mw.loadData ('Module:Sandbox/trappist the monk/ISO 639 name/ISO 639-2');		-- ISO 639-2 language codes / names; to be moved to Module:Language/data/ISO 639-2
local part3_data = mw.loadData ('Module:Language/data/ISO 639-3');				-- existing data module


local function iso_639_name (frame)
	local args = getArgs(frame);
	local code = args[1]:lower();
	
	if 2 > #code or 3 < #code then												-- 639 codes are 2 or three characters only
		return 'error: ' .. code .. ' is not an ISO 639 code';
	end
	
	if 2 == #code then
		return part1_data[code][1] or 'error: ' .. code .. ' is not an ISO 639 code';
	else
		return part2_data[code] and part2_data[code][1] or part3_data[code] and part3_data[code][1] or 'error: ' .. code .. ' is not an ISO 639 code';
	end
end

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

return {iso_639_name = iso_639_name};