Module:Era

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Lua

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

Unused module intended for supporting {{Era}} template. Internationalization at Module:I18n/era.

See Also[edit]

Modules related to internationalization (i18n) of dates
{| class="wikitable sortable" border="1"
Module Name Uses Module Used by Module Used by Template Comment
Module:DateI18n Module:I18n/date Module:ISOdate Template:Date Create date string in any language
Module:ISOdate Module:DateI18n Module:Complex date Template:ISOdate & Template:ISOyear Parse YYYY-MM-DD date string
Module:Roman Module:Complex date
Module:Ordinal
Template:Roman Create Roman numerals
Module:Ordinal Module:I18n/ordinal
Module:Roman
Module:Complex date Template:Ordinal Create Ordinal numerals
Module:Complex date Module:I18n/complex date
Module:ISOdate
Module:Roman
Module:Ordinal
Template:Other date (not deployed yet) Create complex date phrases in many languages

|}

Code

local p = {}

local langSwitch = require('Module:LangSwitch')._langSwitch
local i18n = require('Module:i18n/era')
local maintenancecat = 'Pages with incorrect usage of Module:Era'

function p._era(datestr, era, lang)

	if not datestr or datestr == '' then
		return nil
	end
	if not era or era == '' then
		return datestr
	end

	era = string.upper(era) -- find the right key in the Module:I18n/era table

	if (era == '') then
		era = nil
	elseif (era == 'BEFORE PRESENT') then
		era = 'BP'
	elseif (era == 'BCE') then
		era = 'BC'
	elseif (era == 'CE') then
		era = 'AD'
	end

	if (not i18n[era]) then
		local namespace = mw.title.getCurrentTitle().namespace
		local maintenancestr = ''
		if (namespace == 0) or (namespace == 6) or (namespace == 14) then
				maintenancestr = '[[Category:' .. maintenancecat .. ']]'
		end
		return datestr .. '&nbsp;' .. '<span class=error>' .. era .. '</span>' .. maintenancestr
	end
	local erastr = langSwitch(i18n[era], lang)
	erastr = mw.ustring.gsub(erastr, '$date', datestr) -- as gsub returns 2 values declare before returning it

	return erastr
end

function p.era(frame)
	local args= frame.args 
	local lang = frame.args.lang
	if lang == '' then
		lang = frame:preprocess('{{int:lang}}')
	end
	return p._era(args['date'], args['era'], lang)
end
return p