Module:Century
Jump to navigation
Jump to search
Lua
CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules
Uses Lua: |
Usage
[edit]{{#invoke:Century|century}}
local century = require('Module:Century')._century
Code
require('strict')
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local langSwitch = require('Module:LangSwitch')._langSwitch
local error_message = require('Module:Error')['error']
local roman_value = require('Module:Roman')._Numeral
local p = {}
local function dir(lang)
if mw.language.new(lang):isRTL() then
return "rtl"
else
return "ltr"
end
end
local function bc_text(n, lang)
if n < 0 then
return require('Module:BC AD')._BC({['lang'] = lang})
else
return ''
end
end
local function formatted_n(n, lang)
return require('Module:Formatnum').formatNum(math.abs(n), lang, '', false)
end
function p._century(args, pagetitle)
local n = tonumber(args[1])
if not n or n ~= math.floor(n) then
return error_message({'First parameter is not an integer'})
end
local n_abs = math.abs(n)
local n_last_digit = n_abs % 10
local n_last_two_digits = n_abs % 100
local n_year_start = n_abs * 100 - 100
local roman_n = roman_value(n_abs)
local lang = args.lang or mw.getCurrentFrame():preprocess("{{Int:Lang}}")
-- Bengali
local bn_suffix
if n_last_digit == 2 or n_last_digit == 3 then
bn_suffix = 'য়'
elseif n_last_digit == 4 then
bn_suffix = 'র্থ়'
elseif n_last_digit == 6 then
bn_suffix = 'ষ্ঠ'
else
bn_suffix = 'ম'
end
local bn_text = mw.text.trim(bc_text(n, 'bn') .. ' ' .. formatted_n(n, 'bn') .. bn_suffix .. ' শতকের')
-- English
local hyphen_text
if yesno(args.hyphen or false) then
hyphen_text = '-'
else
hyphen_text = ' '
end
local en_suffix
if 11 <= n_last_two_digits and n_last_two_digits <= 19 then
en_suffix = 'th'
elseif n_last_digit == 1 then
en_suffix = 'st'
elseif n_last_digit == 2 then
en_suffix = 'nd'
elseif n_last_digit == 3 then
en_suffix = 'rd'
else
en_suffix = 'th'
end
local en_text = mw.text.trim(n_abs .. en_suffix .. hyphen_text .. 'century ' .. bc_text(n, 'en'))
-- French
local fr_suffix
if n_abs == 1 then
fr_suffix = '<sup>er</sup>'
else
fr_suffix = '<sup>e</sup>'
end
local fr_text = mw.text.trim(roman_n .. fr_suffix .. ' siècle ' .. bc_text(n, 'fr'))
-- Galician
local gl_prefix
if n < 0 then
gl_prefix = bc_text(n, 'gl') .. '-'
else
gl_prefix = bc_text(n, 'gl')
end
local gl_text = 'século ' .. gl_prefix .. roman_n
-- Interlingua
local ia_suffix
if n_last_digit == 1 or n_last_digit == 7 then
ia_suffix = '<sup>me</sup>'
elseif n_last_digit == 2 then
ia_suffix = '<sup>nde</sup>'
elseif n_last_digit == 3 then
ia_suffix = '<sup>tie</sup>'
elseif n_last_digit == 8 then
ia_suffix = '<sup>ve</sup>'
elseif n_last_digit == 9 then
ia_suffix = '<sup>ne</sup>'
else
ia_suffix = '<sup>te</sup>'
end
local ia_text = mw.text.trim(n_abs .. ia_suffix .. ' seculo ' .. bc_text(n, 'ia'))
-- Macedonian
local mk_suffix
if n_last_digit == 0 or n_last_digit == 5 or n_last_digit == 9 then
mk_suffix = 'т'
elseif n_last_digit == 1 then
mk_suffix = 'в'
elseif n_last_digit == 2 then
mk_suffix = 'р'
elseif n_last_digit == 7 or n_last_digit == 8 then
mk_suffix = 'м'
else
mk_suffix = ''
end
local mk_text = mw.text.trim(n_abs .. '-' .. mk_suffix .. 'иот век ' .. bc_text(n, 'mk'))
-- Jèrriais or Guernésiais
local nrf_suffix
if n_abs == 1 then
nrf_suffix = '<sup>yi</sup>'
else
nrf_suffix = '<sup>e</sup>'
end
local nrf_text = mw.text.trim(roman_n .. nrf_suffix .. ' siaeclle ' .. bc_text(n, 'nrf'))
local nrf_fr_text = mw.text.trim(roman_n .. nrf_suffix .. ' syiclle ' .. bc_text(n, 'nrf-fr'))
local nrf_gg_text = mw.text.trim(roman_n .. nrf_suffix .. ' siécl’ye ' .. bc_text(n, 'nrf-gg'))
local nrf_je_text = mw.text.trim(roman_n .. nrf_suffix .. ' siaeclle ' .. bc_text(n, 'nrf-je'))
-- LangSwitch
local text_args = {
['af'] = mw.text.trim(n_abs .. 'de eeu ' .. bc_text(n, 'af')),
['am'] = mw.text.trim(n_abs .. 'ኛው ምዕተ ዓመት ' .. bc_text(n, 'am')),
['an'] = mw.text.trim('sieglo ' .. roman_n .. ' ' .. bc_text(n, 'an')),
['ang'] = mw.text.trim(n_abs .. ' ȝēarhundred ' .. bc_text(n, 'ang')),
['ar'] = mw.text.trim('القرن ' .. formatted_n(n, 'ar') .. ' ' .. bc_text(n, 'ar')),
['arz'] = mw.text.trim('القرن ' .. formatted_n(n, 'arz') .. ' ' .. bc_text(n, 'arz')),
['ast'] = mw.text.trim(roman_n .. '<sup>u</sup> sieglu ' .. bc_text(n, 'ast')),
['av'] = roman_n .. ' гІасру',
['az'] = mw.text.trim(bc_text(n, 'az') .. roman_n .. ' əsr'),
['azb'] = formatted_n(n, 'azb') .. '. یوز ایل',
['ba'] = mw.text.trim(roman_n .. ' быуат ' .. bc_text(n, 'ba')),
['ban'] = mw.text.trim('abad ka‑' .. n_abs .. ' ' .. bc_text(n, 'ban')),
['be'] = mw.text.trim(n_abs .. ' стагоддзе ' .. bc_text(n, 'be')),
['be-tarask'] = mw.text.trim(roman_n .. ' стагодзьдзе ' .. bc_text(n, 'be-tarask')),
['bg'] = mw.text.trim(n_abs .. '‑ти век ' .. bc_text(n, 'bg')),
['bn'] = bn_text,
['br'] = mw.text.trim(roman_n .. 'vet kantved ' .. bc_text(n, 'br')),
['bs'] = mw.text.trim(n_abs .. '. vijek ' .. bc_text(n, 'bs')),
['ca'] = mw.text.trim('segle ' .. roman_n .. ' ' .. bc_text(n, 'ca')),
['cdo'] = mw.text.trim(n_abs .. ' sié-gī ' .. bc_text(n, 'cdo')),
['ce'] = mw.text.trim(roman_n .. ' бӀешо ' .. bc_text(n, 'ce')),
['ceb'] = mw.text.trim('ika‑' .. n_abs .. 'ng siglo ' .. bc_text(n, 'ceb')),
['co'] = mw.text.trim(roman_n .. ' seculu ' .. bc_text(n, 'co')),
['cs'] = mw.text.trim(n_abs .. '. století ' .. bc_text(n, 'cs')),
['cv'] = mw.text.trim(bc_text(n, 'cv') .. roman_n .. ' ĕмĕр'),
['cy'] = mw.text.trim(n_abs .. 'fed ganrif ' .. bc_text(n, 'cy')),
['da'] = mw.text.trim(n_abs .. '. århundrede ' .. bc_text(n, 'da')),
['de'] = mw.text.trim(n_abs .. '. Jahrhundert ' .. bc_text(n, 'de')),
['diq'] = mw.text.trim('seserra ' .. n_abs .. 'ine ' .. bc_text(n, 'diq')),
['dsb'] = mw.text.trim(n_abs .. '. stolěśe ' .. bc_text(n, 'dsb')),
['el'] = mw.text.trim(n_abs .. 'ος αιώνας ' .. bc_text(n, 'el')),
['eml'] = mw.text.trim(roman_n .. ' sécol ' .. bc_text(n, 'eml')),
['en'] = en_text,
['eo'] = mw.text.trim(n_abs .. '‑a jarcento ' .. bc_text(n, 'eo')),
['es'] = mw.text.trim('siglo ' .. roman_n .. ' ' .. bc_text(n, 'es')),
['et'] = mw.text.trim(n_abs .. '. sajand ' .. bc_text(n, 'et')),
['eu'] = mw.text.trim(bc_text(n, 'eu') .. roman_n .. '. mendea'),
['ext'] = mw.text.trim('sigru ' .. roman_n .. ' ' .. bc_text(n, 'ext')),
['fa'] = mw.text.trim(formatted_n(n, 'fa') .. ' م<!--x--> قرن ' .. bc_text(n, 'fa')),
['fi'] = mw.text.trim(n_year_start .. '‑luku ' .. bc_text(n, 'fi')),
['fo'] = mw.text.trim(n_abs .. '. øld ' .. bc_text(n, 'fo')),
['fr'] = fr_text,
['frr'] = mw.text.trim(n_abs .. '. juarhunert ' .. bc_text(n, 'frr')),
['fy'] = mw.text.trim(n_abs .. 'e ieu ' .. bc_text(n, 'fy')),
['ga'] = mw.text.trim(n_abs .. 'ú haois ' .. bc_text(n, 'ga')),
['gan'] = mw.text.trim(bc_text(n, 'gan') .. n_abs .. '世紀'),
['gd'] = mw.text.trim(n_abs .. 'mh Linn ' .. bc_text(n, 'gd')),
['gl'] = gl_text,
['gsw'] = mw.text.trim(n_abs .. '. Jahrhundert ' .. bc_text(n, 'gsw')),
['gu'] = mw.text.trim(formatted_n(n, 'gu') .. ' મી સદી ' .. bc_text(n, 'gu')),
['gv'] = mw.text.trim(n_abs .. 'oo eash ' .. bc_text(n, 'gv')),
['ha'] = mw.text.trim('karni na ' .. n_abs .. ' ' .. bc_text(n, 'ha')),
['haw'] = mw.text.trim(n_abs .. ' kenekulia ' .. bc_text(n, 'haw')),
['he'] = mw.text.trim('המאה <!--x--> ה‑' .. n_abs .. ' ' .. bc_text(n, 'he')),
['hi'] = mw.text.trim(formatted_n(n, 'hi') .. 'वीं शताब्दी ' .. bc_text(n, 'hi')),
['hmn'] = mw.text.trim(n_abs .. ' xyoo pua ' .. bc_text(n, 'hmn')),
['hr'] = mw.text.trim(n_abs .. '. stoljeće ' .. bc_text(n, 'hr')),
['hsb'] = mw.text.trim(n_abs .. '. lětstotk ' .. bc_text(n, 'hsb')),
['ht'] = mw.text.trim(n_abs .. 'yèm syèk ' .. bc_text(n, 'ht')),
['hu'] = mw.text.trim(bc_text(n, 'hu') .. n_abs .. '. század'),
['hy'] = mw.text.trim(bc_text(n, 'hy') .. n_abs .. '‑րդ դար'),
['ia'] = ia_text,
['id'] = mw.text.trim('abad ke‑' .. n_abs .. ' ' .. bc_text(n, 'id')),
['ig'] = mw.text.trim('narị afọ nke 20 ' .. bc_text(n, 'ig')),
['io'] = mw.text.trim(n_abs .. 'ma yarcento ' .. bc_text(n, 'io')),
['is'] = mw.text.trim(n_abs .. '. öldin ' .. bc_text(n, 'is')),
['it'] = mw.text.trim(roman_n .. ' secolo ' .. bc_text(n, 'it')),
['ja'] = mw.text.trim(bc_text(n, 'ja') .. n_abs .. '世紀'),
['jv'] = mw.text.trim('abad kaping‑' .. n_abs .. ' ' .. bc_text(n, 'jv')),
['ka'] = mw.text.trim(bc_text(n, 'ka') .. roman_n .. ' საუკუნე'),
['kk'] = mw.text.trim(bc_text(n, 'kk') .. n_abs .. ' ғасыр'),
['km'] = mw.text.trim('សតវត្សទី ' .. formatted_n(n, 'km') .. ' ' .. bc_text(n, 'km')),
['kn'] = mw.text.trim(bc_text(n, 'kn') .. ' ' .. formatted_n(n, 'kn') .. ' ನೇ ಶತಮಾನ'),
['ko'] = mw.text.trim(bc_text(n, 'ko') .. n_abs .. '세기'),
['ku'] = mw.text.trim('sedsala ' .. n_abs .. '‑an ' .. bc_text(n, 'ku')),
['kw'] = mw.text.trim(n_abs .. 'ves kansbledhen ' .. bc_text(n, 'kw')),
['ky'] = mw.text.trim(bc_text(n, 'ky') .. n_abs .. '‑кылым'),
['la'] = mw.text.trim('saeculum ' .. n_abs .. ' ' .. bc_text(n, 'la')),
['lb'] = mw.text.trim(n_abs .. '. Joerhonnert ' .. bc_text(n, 'lb')),
['lez'] = mw.text.trim(roman_n .. ' виш йис ' .. bc_text(n, 'lez')),
['lfn'] = mw.text.trim('sentenio ' .. n_abs .. ' ' .. bc_text(n, 'lfn')),
['li'] = mw.text.trim(n_abs .. 'de iew ' .. bc_text(n, 'li')),
['lij'] = mw.text.trim(roman_n .. ' secolo ' .. bc_text(n, 'lij')),
['lmo'] = mw.text.trim('sécul ' .. roman_n .. ' ' .. bc_text(n, 'lmo')),
['lo'] = mw.text.trim('ສະຕະວັດທີ ' .. n_abs .. ' ' .. bc_text(n, 'lo')),
['lt'] = mw.text.trim(roman_n .. ' amžius ' .. bc_text(n, 'lt')),
['lv'] = mw.text.trim(n_abs .. '. gadsimts ' .. bc_text(n, 'lv')),
['map-bms'] = mw.text.trim('abad kaping‑' .. n_abs .. ' ' .. bc_text(n, 'map-bms')),
['mg'] = mw.text.trim('taonjato faha‑' .. n_abs .. ' ' .. bc_text(n, 'mg')),
['mhr'] = mw.text.trim(bc_text(n, 'mhr') .. roman_n .. ' курым'),
['mk'] = mk_text,
['mi'] = mw.text.trim('rautau ' .. n_abs .. ' ' .. bc_text(n, 'mi')),
['ml'] = mw.text.trim(bc_text(n, 'ml') .. ' ' .. formatted_n(n, 'ml') .. '‑ആം നൂറ്റാണ്ടിൽ'),
['mn'] = mw.text.trim(bc_text(n, 'mn') .. n_abs .. '‑р зуун'),
['mr'] = mw.text.trim(bc_text(n, 'mr') .. ' ' .. formatted_n(n, 'mr') .. ' व्या शतकात'),
['ms'] = mw.text.trim('abad ke‑' .. n_abs .. ' ' .. bc_text(n, 'ms')),
['mt'] = mw.text.trim('seklu ' .. n_abs .. ' ' .. bc_text(n, 'mt')),
['mwl'] = mw.text.trim('século ' .. roman_n .. ' ' .. bc_text(n, 'mwl')),
['my'] = mw.text.trim(bc_text(n, 'my') .. ' ' .. formatted_n(n, 'my') .. ' ရာစုနှစ်'),
['myv'] = mw.text.trim(roman_n .. ' пинге ' .. bc_text(n, 'myv')),
['nah'] = mw.text.trim('mācuīlpōhualxihuitl ' .. roman_n .. ' ' .. bc_text(n, 'nah')),
['nan'] = mw.text.trim(n_abs .. ' sè-kí ' .. bc_text(n, 'nan')),
['nap'] = mw.text.trim(roman_n .. ' seculo ' .. bc_text(n, 'nap')),
['nb'] = mw.text.trim(n_abs .. '. århundre ' .. bc_text(n, 'nb')),
['nds'] = mw.text.trim(n_abs .. '. Johrhunnert ' .. bc_text(n, 'nds')),
['nds-nl'] = mw.text.trim(n_abs .. 'e eeuw ' .. bc_text(n, 'nds-nl')),
['nl'] = mw.text.trim(n_abs .. 'e eeuw ' .. bc_text(n, 'nl')),
['nn'] = mw.text.trim(n_year_start .. '‑talet ' .. bc_text(n, 'nn')),
['nrf'] = nrf_text,
['nrf-fr'] = nrf_fr_text,
['nrf-gg'] = nrf_gg_text,
['nrf-je'] = nrf_je_text,
['nso'] = mw.text.trim('ngwagakgolo ' .. n_abs .. ' ' .. bc_text(n, 'nso')),
['ny'] = mw.text.trim('zaka za zana la ' .. n_abs .. ' ' .. bc_text(n, 'ny')),
['oc'] = mw.text.trim('sègle ' .. roman_n .. ' ' .. bc_text(n, 'oc')),
['or'] = mw.text.trim(bc_text(n, 'or') .. ' ' .. formatted_n(n, 'or') .. ' ତମ ଶତାବ୍ଦୀ'),
['pl'] = mw.text.trim(roman_n .. ' wiek ' .. bc_text(n, 'pl')),
['ps'] = mw.text.trim(formatted_n(n, 'ps') .. ' پیړۍ ' .. bc_text(n, 'ps')),
['pt'] = mw.text.trim('século ' .. roman_n .. ' ' .. bc_text(n, 'pt')),
['qu'] = mw.text.trim(n_abs .. ' ñiqin pachakwata ' .. bc_text(n, 'qu')),
['ro'] = mw.text.trim('secolul al ' .. roman_n .. '‑lea ' .. bc_text(n, 'ro')),
['ru'] = mw.text.trim(roman_n .. ' век ' .. bc_text(n, 'ru')),
['rue'] = mw.text.trim(roman_n .. '. стороча ' .. bc_text(n, 'rue')),
['rw'] = mw.text.trim('ikinyejana cya ' .. n_abs .. ' ' .. bc_text(n, 'rw')),
['sah'] = mw.text.trim(roman_n .. ' үйэ ' .. bc_text(n, 'sah')),
['sc'] = mw.text.trim('sèculo ' .. roman_n .. ' ' .. bc_text(n, 'sc')),
['scn'] = mw.text.trim('sèculu ' .. roman_n .. ' ' .. bc_text(n, 'scn')),
['sd'] = mw.text.trim(formatted_n(n, 'sd') .. ' صدي ' .. bc_text(n, 'sd')),
['sgs'] = mw.text.trim(roman_n .. ' omžios ' .. bc_text(n, 'sgs')),
['sh'] = mw.text.trim(n_abs .. '. vijek ' .. bc_text(n, 'sh')),
['shn'] = mw.text.trim('ပီႁူဝ်ပၢၵ်ႇ ' .. formatted_n(n, 'shn') .. ' ' .. bc_text(n, 'shn')),
['si'] = mw.text.trim(bc_text(n, 'si') .. ' ' .. formatted_n(n, 'si') .. ' වන සියවස'),
['sk'] = mw.text.trim(n_abs .. '. storočie ' .. bc_text(n, 'sk')),
['sl'] = mw.text.trim(n_abs .. '. stoletje ' .. bc_text(n, 'sl')),
['sn'] = mw.text.trim('zana ramakore rechi' .. n_abs .. ' ' .. bc_text(n, 'sn')),
['so'] = mw.text.trim('qarnigii ' .. n_abs .. '‑aad ' .. bc_text(n, 'so')),
['sq'] = mw.text.trim('shekulli ' .. roman_n .. ' ' .. bc_text(n, 'sq')),
['sr'] = mw.text.trim(n_abs .. '. век ' .. bc_text(n, 'sr')),
['stq'] = mw.text.trim(n_abs .. '. Jierhunnert ' .. bc_text(n, 'stq')),
['su'] = mw.text.trim('abad ka‑' .. n_abs .. ' ' .. bc_text(n, 'su')),
['sv'] = mw.text.trim(n_year_start .. '‑talet ' .. bc_text(n, 'sv')),
['sw'] = mw.text.trim('karne ya ' .. n_abs .. ' ' .. bc_text(n, 'sw')),
['ta'] = mw.text.trim(bc_text(n, 'ta') .. ' ' .. formatted_n(n, 'ta') .. ' ஆம் நூற்றாண்டு'),
['te'] = mw.text.trim(bc_text(n, 'te') .. ' ' .. formatted_n(n, 'te') .. ' వ శతాబ్దం'),
['tg'] = mw.text.trim('асри ' .. n_abs .. ' ' .. bc_text(n, 'tg')),
['th'] = mw.text.trim(bc_text(n, 'th') .. 'ศตวรรษที่ ' .. n_abs),
['tk'] = mw.text.trim(bc_text(n, 'tk') .. n_abs .. '‑njy asyr'),
['tl'] = mw.text.trim('ika‑' .. n_abs .. ' siglo ' .. bc_text(n, 'tl')),
['tr'] = mw.text.trim(bc_text(n, 'tr') .. n_abs .. '. yüzyıl'),
['tt'] = mw.text.trim(bc_text(n, 'tt') .. roman_n .. ' гасыр'),
['ug'] = mw.text.trim(bc_text(n, 'ug') .. ' ' .. formatted_n(n, 'ug') .. '‑ئەسىر'),
['uk'] = mw.text.trim(roman_n .. ' століття ' .. bc_text(n, 'uk')),
['ur'] = mw.text.trim(formatted_n(n, 'ur') .. ' ویں <!--x--> صدی ' .. bc_text(n, 'ur')),
['uz'] = mw.text.trim(bc_text(n, 'uz') .. roman_n .. '‑asr'),
['vec'] = mw.text.trim(roman_n .. ' secolo ' .. bc_text(n, 'vec')),
['vi'] = mw.text.trim('thế kỷ ' .. n_abs .. ' ' .. bc_text(n, 'vi')),
['vls'] = mw.text.trim(n_abs .. 'e eeuw ' .. bc_text(n, 'vls')),
['vro'] = mw.text.trim(n_abs .. '. aastagasada ' .. bc_text(n, 'vro')),
['wa'] = mw.text.trim(n_abs .. 'inme sieke ' .. bc_text(n, 'wa')),
['war'] = mw.text.trim('ika‑' .. n_abs .. ' nga gatostuig ' .. bc_text(n, 'war')),
['wuu'] = mw.text.trim(bc_text(n, 'wuu') .. n_abs .. '世纪'),
['xh'] = mw.text.trim('ngenkulungwane yama‑' .. n_abs .. ' ' .. bc_text(n, 'xh')),
['xmf'] = mw.text.trim(bc_text(n, 'xmf') .. roman_n .. ' ოშწანურა'),
['yi'] = mw.text.trim(n_abs .. ' יאָרהונדערט ' .. bc_text(n, 'yi')),
['yo'] = mw.text.trim('ọrúndún ' .. n_abs .. 'k ' .. bc_text(n, 'yo')),
['yue'] = mw.text.trim(bc_text(n, 'yue') .. n_abs .. '世紀'),
['zh'] = mw.text.trim(bc_text(n, 'zh') .. n_abs .. '世纪'),
['zu'] = mw.text.trim('ngekhulu lama‑' .. n_abs .. ' ' .. bc_text(n, 'zu'))
}
-- add bdi tags
-- lets not return the whole list to langSwitch unless that is what is asked for.
if pagetitle == nil or "Template:Century" or "Template:Century/sandbox" then
for k, v in pairs(text_args) do
text_args[k] = '<bdi lang="' .. k .. '" dir="' .. dir(k) .. '">' .. v .. '</bdi>'
end
return langSwitch(text_args, lang)
else
return '<bdi lang="' .. lang .. '" dir="' .. dir(lang) .. '">' .. text_args[lang] .. '</bdi>'
end
end
function p.century(frame)
local pagetitle = frame:getParent():getTitle()
return p._century(getArgs(frame), pagetitle)
end
return p