Kontent qismiga oʻtish

Modul:Month translator

Vikipediya, erkin ensiklopediya

Bu modul uchun Modul:Month translator/doc nomli hujjat sahifasini yaratishingiz mumkin

require('strict')
local getArgs = require ('Module:Arguments').getArgs;

local data = mw.loadData ('Module:month translator/data');

local function _month_xlate (args_t)
	local t = {};
	local day, month, year;
	
	if 'dump' == args_t[1] then												 
		return mw.dumpObject (data.month_names_t);
	end
	if not args_t[1] then return nil end
	for i, pattern in ipairs (data.patterns) do								
		local c1, c2, c3;														

		c1, c2, c3 = mw.ustring.match (mw.text.trim (args_t[1]), pattern[1]);	
		if c1 then															

			t = {
				[pattern[2] or 'x'] = c1,									
				[pattern[3] or 'x'] = c2,										
				[pattern[4] or 'x'] = c3,								
				};
			day = t.d or '';												
			month = mw.ustring.lower (t.m or '');								
			month = data.override_names[month] or data.month_names_t[month];
			year= t.y or '';

			if month then
				local df = table.concat ({pattern[2], pattern[3], pattern[4]}, '');	

				if 'dmy' == df then											
					return table.concat ({day, month, year}, ' ');			
				elseif 'my' == df then										
					return table.concat ({month, year}, ' ');					
				elseif 'mdy' == df then										
					return string.format ('%s %s, %s', month, day, year);		
				elseif 'm' == df then										
					return month;										
				end
			end
			break;												
		end
	end	
	return args_t[1];														
end

local function month_xlate (frame)
	return _month_xlate (getArgs (frame));
end

return {
	month_xlate = month_xlate,
	_month_xlate = _month_xlate
	};