مۆدیوول:ISO 639/data/altnames/make

لە ئینسایکڵۆپیدیای ئازادی ویکیپیدیاوە
Jump to navigation Jump to search
بەڵگەدارکردنی مۆدیوول[دروست بکە]
-- Keep Here
local p = {}

function p.extract (frame)
	local page = mw.title.getCurrentTitle();																	
	local content = page:getContent();																				
	local lang_table = {};																							
	local file_date = 'File-Date: ' .. frame.args["file-date"];
	local data = mw.loadData("Module:ISO 639/data")
	
	local remove = {["-"]="DASH",[" "]="SPACE",["%("]="BRAKCETOPEN",["%)"]="BRACKETCLOSE",["'"]="APOSTROPHE",["’"]="APOSTROPHE2",["’"]="APOSTROPHE2",["_"]="UNDERLINE",[","]="COMMA"}
	local add = {["DASH"]="-",["SPACE"]=" ",["BRAKCETOPEN"]="(",["BRACKETCLOSE"]=")",["APOSTROPHE"]="'",["APOSTROPHE2"]="’",["APOSTROPHE2"]="’",["UNDERLINE"]="_",["COMMA"]=","}
	
	for k,v in pairs(remove) do
		content = mw.ustring.gsub(content,k,v)
	end
	
	for code, print, invert in mw.ustring.gmatch (content, '\n(%w%w%w)\t*(%w*)\t*(%w*)') do
		
		local name = data[code].name
		
		for k,v in pairs(remove) do
			name = mw.ustring.gsub(name,k,v)
		end
		
		local print  = string.gsub (print ,name,"")
		local invert  = string.gsub (invert ,name,"")
		
		if print == invert then
			invert = ""
		end
		
		--if print == mw.ustring.match (print,"%a+%A+%a+") then
		--	print = mw.ustring.gsub (print,"	","","")
		--end
		
		if invert ~= "" then
			for k,v in pairs(add) do
				invert = mw.ustring.gsub(invert,k,v)
			end
			table.insert(lang_table,"[\"" .. invert .. "\"] = \"" .. code  .. "\"");
		end
		
		if print ~= "" then
			for k,v in pairs(add) do
				print = mw.ustring.gsub(print,k,v)
			end
			table.insert(lang_table,"[\"" .. print .. "\"] = \"" .. code  .. "\"");
		end
	end
	
	
	return "<br /><pre>-- " .. file_date .. "<br>-- [&quot;Name&quot;] = {&quot;Part 3&quot;} <br>-- You can update the code using [[Module:ISO 639/data/altnames/make]]<br>-- For more information about ISO 639 see [[ISO 639]]<br><br>return {<br />&#9;" .. table.concat (lang_table, ',<br />&#9;') .. "<br />&#9;}<br />" .. "</pre>";
end

return p;