Jump to content
Toggle menu
  • 3 articles
  • 75 files
  • 7 users
  • 37.9K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Ordinal: Difference between revisions

From Neodyland Wiki
m Changed protection level for "Module:Ordinal": downgraded protection level per consensus ([Move=Allow only template editors and administrators] (indefinite) [Edit=Allow only template editors and administrators] (indefinite))
eliminate need for Module:Roman
 
(One intermediate revision by the same user not shown)
Line 15: Line 15:
-- =======================================
-- =======================================
local i18n      = require('Module:I18n/ordinal')        -- get localized translations of ordinals
local i18n      = require('Module:I18n/ordinal')        -- get localized translations of ordinals
local LangSwitch = require('Module:LangSwitch')          -- get LangSwitch function
local yesno      = require('Module:Yesno')              -- boolean value interpretation
local yesno      = require('Module:Yesno')              -- boolean value interpretation
local formatnum  = require('Module:Formatnum')          -- number formatting
local formatnum  = require('Module:Formatnum')          -- number formatting
local roman      = require('Module:Roman')              -- roman numeral conversion (primarily for French)


-- =======================================
-- =======================================
-- === Private Functions =================
-- === Private Functions =================
-- =======================================
-- =======================================
------------------------------------------------------------------------------
-- code equivalent to https://commons.wikimedia.org/wiki/Template:LangSwitch
local function langSwitch(list,lang)
local langList = mw.language.getFallbacksFor(lang)
table.insert(langList,1,lang)
table.insert(langList,math.max(#langList,2),'default')
for i,language in ipairs(langList) do
if list[language] then
return list[language]
end
end
return nil
end


--[[
--[[
Line 35: Line 48:
end
end


--[[
This function returns a string containing the input value formatted as a Roman numeral. 
It works for values between 0 and 3999.
]]
local function Roman(value)
local d0, d1, d2, d3, i0, i1, i2, i3
d0 = { [0] = '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX' }
    d1 = { [0] = '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC' }
    d2 = { [0] = '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM' }
    d3 = { [0] = '', 'M', 'MM', 'MMM'}
local result = ''
if ((value >= 0) and (value < 4000)) then
i3 = math.floor(value / 1e3) 
i2 = math.floor(value / 1e2) % 10
i1 = math.floor(value / 1e1) % 10
i0 = math.floor(value / 1e0) % 10
result = d3[i3] .. d2[i2] .. d1[i1] .. d0[i0]
end
return result
end
--[[
--[[
Line 41: Line 76:
local function FormatNum( value, lang )
local function FormatNum( value, lang )
if lang == 'roman' then
if lang == 'roman' then
return roman._Numeral(value)
return Roman(value)
else
else
return formatnum.formatNum(value, lang)
return formatnum.formatNum(value, lang)
Line 84: Line 119:
-- which scheme should we use to format the ordinal value?  
-- which scheme should we use to format the ordinal value?  
-- Use Fallback module to handle languages groups that map to a supported language
-- Use Fallback module to handle languages groups that map to a supported language
local schemeSpecifier = LangSwitch._langSwitch(i18n.SchemeFromLang, lang)
local schemeSpecifier = langSwitch(i18n.SchemeFromLang, lang)
-- Look up scheme based on scheme specifier (and possibly style)
-- Look up scheme based on scheme specifier (and possibly style)
Cookies help us deliver our services. By using our services, you agree to our use of cookies.