<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AOrdinal-cd</id>
	<title>Module:Ordinal-cd - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3AOrdinal-cd"/>
	<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Ordinal-cd&amp;action=history"/>
	<updated>2026-06-12T22:05:25Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.3</generator>
	<entry>
		<id>https://mywikibiz.com/index.php?title=Module:Ordinal-cd&amp;diff=478846&amp;oldid=prev</id>
		<title>Zoran: Pywikibot 6.4.0</title>
		<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Ordinal-cd&amp;diff=478846&amp;oldid=prev"/>
		<updated>2021-07-16T05:13:51Z</updated>

		<summary type="html">&lt;p&gt;Pywikibot 6.4.0&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[  &lt;br /&gt;
 &lt;br /&gt;
This template will add the appropriate ordinal suffix to a given integer.&lt;br /&gt;
 &lt;br /&gt;
Please do not modify this code without applying the changes first at Module:Ordinal/sandbox and testing &lt;br /&gt;
at Module:Ordinal/sandbox/testcases and Module talk:Ordinal/sandbox/testcases.&lt;br /&gt;
 &lt;br /&gt;
Authors and maintainers:&lt;br /&gt;
* User:RP88&lt;br /&gt;
 &lt;br /&gt;
]]&lt;br /&gt;
 &lt;br /&gt;
-- =======================================&lt;br /&gt;
-- === Dependencies ======================&lt;br /&gt;
-- =======================================&lt;br /&gt;
local i18n       = require('Module:I18n/ordinal')        -- get localized translations of ordinals&lt;br /&gt;
local LangSwitch = require('Module:LangSwitch')          -- get LangSwitch function&lt;br /&gt;
local yesno      = require('Module:Yesno')               -- boolean value interpretation&lt;br /&gt;
local formatnum  = require('Module:Formatnum')           -- number formatting&lt;br /&gt;
&lt;br /&gt;
-- =======================================&lt;br /&gt;
-- === Private Functions =================&lt;br /&gt;
-- =======================================&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Helper function to generate superscripted content&lt;br /&gt;
]]&lt;br /&gt;
local function Superscript( str, superscript, nosup, period )&lt;br /&gt;
	if superscript and (not nosup) and (str ~= '') then&lt;br /&gt;
		return period .. '&amp;lt;sup&amp;gt;' .. str .. '&amp;lt;/sup&amp;gt;'&lt;br /&gt;
	else&lt;br /&gt;
		return str&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
	&lt;br /&gt;
--[[&lt;br /&gt;
Helper function to call Formatnum.&lt;br /&gt;
]]&lt;br /&gt;
local function FormatNum( value, lang )&lt;br /&gt;
	if lang == 'roman' then&lt;br /&gt;
		return require(&amp;quot;Module:Roman-cd&amp;quot;)._Numeral(value)&lt;br /&gt;
	else&lt;br /&gt;
		return formatnum.formatNum(value, lang)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
	&lt;br /&gt;
--[[&lt;br /&gt;
Helper function to add append a category to a message.&lt;br /&gt;
]]&lt;br /&gt;
local function output_cat( message, category )&lt;br /&gt;
    return message .. '[[Category:' .. category .. ']]'&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
Helper function to handle error messages.&lt;br /&gt;
]]&lt;br /&gt;
local function output_error( error_str, value )&lt;br /&gt;
	error_str = '&amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;&amp;lt;span title=&amp;quot;Error: ' .. error_str .. '&amp;quot;&amp;gt;' .. value .. '&amp;lt;/span&amp;gt;&amp;lt;/strong&amp;gt;'&lt;br /&gt;
    return output_cat(error_str, 'Errors reported by Module Ordinal');&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
This function is the core functionality for adding the appropriate ordinal suffix to a given integer.&lt;br /&gt;
]]&lt;br /&gt;
local function OrdinalCore( value, lang, style, gender, nosup )	&lt;br /&gt;
	-- Just in case someone breaks the internationalization code, fix the english scheme&lt;br /&gt;
	if i18n.SchemeFromLang['en'] == nil then&lt;br /&gt;
		i18n.SchemeFromLang['en'] = 'en-scheme'&lt;br /&gt;
	end	&lt;br /&gt;
	if i18n.Scheme['en-scheme'] == nil then&lt;br /&gt;
		i18n.Scheme['en-scheme'] = {rules = 'skip-tens', superscript = true, suffix = 'th', suffix_1 = 'st', suffix_2 = 'nd', suffix_3 = 'rd'}&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Add the default scheme (i.e. &amp;quot;&amp;lt;value&amp;gt;.&amp;quot;)&lt;br /&gt;
	if i18n.SchemeFromLang['default'] == nil then&lt;br /&gt;
		i18n.SchemeFromLang['default'] = 'period-scheme'&lt;br /&gt;
	end	&lt;br /&gt;
	if i18n.Scheme['period-scheme'] == nil then&lt;br /&gt;
		i18n.Scheme['period-scheme'] = {rules = 'suffix', suffix = '.'}&lt;br /&gt;
	end&lt;br /&gt;
		&lt;br /&gt;
	-- which scheme should we use to format the ordinal value? &lt;br /&gt;
	-- Use Fallback module to handle languages groups that map to a supported language&lt;br /&gt;
	local schemeSpecifier = LangSwitch._langSwitch(i18n.SchemeFromLang, lang)&lt;br /&gt;
	&lt;br /&gt;
	-- Look up scheme based on scheme specifier (and possibly style)&lt;br /&gt;
	local scheme = i18n.Scheme[schemeSpecifier .. '/' .. style] or i18n.Scheme[schemeSpecifier]&lt;br /&gt;
	&lt;br /&gt;
	-- process scheme by applying rules identified by Scheme&lt;br /&gt;
	local output = ''&lt;br /&gt;
	local period = (scheme.period and '.') or ''&lt;br /&gt;
	local rules = scheme.rules&lt;br /&gt;
	if rules == 'skip-tens' then&lt;br /&gt;
		local suffix&lt;br /&gt;
		local mod100 = math.floor(math.abs(value)) % 100&lt;br /&gt;
		if (mod100 &amp;gt;= 10) and (mod100 &amp;lt;= 19) then&lt;br /&gt;
			suffix = scheme.suffix or ''&lt;br /&gt;
		else&lt;br /&gt;
			local mod10 = math.floor(math.abs(value)) % 10&lt;br /&gt;
			suffix = scheme['suffix_'..mod10] or scheme.suffix or ''&lt;br /&gt;
		end&lt;br /&gt;
		output = FormatNum(value, scheme.formatlang or lang) .. Superscript( suffix, scheme.superscript, nosup, period)&lt;br /&gt;
	elseif rules == 'suffix' then&lt;br /&gt;
		output = FormatNum(value, scheme.formatlang or lang) .. Superscript( scheme.suffix or '', scheme.superscript, nosup, period)&lt;br /&gt;
	elseif rules == 'prefix' then&lt;br /&gt;
		output = (scheme.prefix or '') .. FormatNum(value, scheme.formatlang or lang)&lt;br /&gt;
	elseif rules == 'mod10-suffix' then&lt;br /&gt;
		local index = math.floor(math.abs(value)) % 10&lt;br /&gt;
		local suffix = scheme['suffix_'..index] or scheme.suffix or ''&lt;br /&gt;
		output = FormatNum(value, scheme.formatlang or lang) .. Superscript( suffix, scheme.superscript, nosup, period)&lt;br /&gt;
	elseif rules == 'gendered-suffix' then&lt;br /&gt;
		local suffix = scheme['suffix_'..gender] or scheme.suffix or ''&lt;br /&gt;
		output = FormatNum(value, scheme.formatlang or lang) .. Superscript( suffix, scheme.superscript, nosup, period)&lt;br /&gt;
	elseif rules == 'gendered-suffix-one' then&lt;br /&gt;
		local suffix&lt;br /&gt;
		if value == 1 then&lt;br /&gt;
			suffix = scheme['suffix_1_'..gender] or scheme['suffix_1'] or scheme.suffix or ''&lt;br /&gt;
		else&lt;br /&gt;
			suffix = scheme['suffix_'..gender] or scheme.suffix or ''&lt;br /&gt;
		end&lt;br /&gt;
		output = FormatNum(value, scheme.formatlang or lang) .. Superscript( suffix, scheme.superscript, nosup, period)&lt;br /&gt;
	elseif rules == 'gendered-suffix-n' then&lt;br /&gt;
		local suffix&lt;br /&gt;
		if value &amp;lt;= 9 then&lt;br /&gt;
			suffix = scheme['suffix_'..value..'_'..gender] or scheme['suffix_'..value] or scheme['suffix_'..gender] or scheme.suffix or ''&lt;br /&gt;
		else&lt;br /&gt;
			suffix = scheme['suffix_'..gender] or scheme.suffix or ''&lt;br /&gt;
		end&lt;br /&gt;
		output = FormatNum(value, scheme.formatlang or lang) .. Superscript( suffix, scheme.superscript, nosup, period)&lt;br /&gt;
	elseif rules == 'suffix-one' then&lt;br /&gt;
		local prefix, suffix&lt;br /&gt;
		if value == 1 then&lt;br /&gt;
			prefix = scheme['prefix_1'] or scheme.prefix or ''&lt;br /&gt;
			suffix = scheme['suffix_1'] or scheme.suffix or ''&lt;br /&gt;
		else&lt;br /&gt;
			prefix = scheme.prefix or ''&lt;br /&gt;
			suffix = scheme.suffix or ''&lt;br /&gt;
		end&lt;br /&gt;
		output = prefix .. FormatNum(value, scheme.formatlang or lang) .. Superscript( suffix, scheme.superscript, nosup, period)&lt;br /&gt;
	elseif rules == 'mod10-gendered-suffix-skip-tens' then&lt;br /&gt;
		local suffix&lt;br /&gt;
		local mod100 = math.floor(math.abs(value)) % 100&lt;br /&gt;
		if (mod100 &amp;gt;= 10) and (mod100 &amp;lt;= 19) then&lt;br /&gt;
			suffix = scheme['suffix_'..gender] or scheme.suffix or ''&lt;br /&gt;
		else&lt;br /&gt;
			local mod10 = math.floor(math.abs(value)) % 10&lt;br /&gt;
			suffix = scheme['suffix_'..mod10..'_'..gender] or scheme['suffix_'..mod10] or scheme['suffix_'..gender] or scheme.suffix or ''&lt;br /&gt;
		end&lt;br /&gt;
		output = FormatNum(value, scheme.formatlang or lang) .. Superscript( suffix, scheme.superscript, nosup, period)&lt;br /&gt;
	elseif rules == 'uk-rules' then&lt;br /&gt;
		local suffix&lt;br /&gt;
		local mod100 = math.floor(math.abs(value)) % 100&lt;br /&gt;
		local mod1000 = math.floor(math.abs(value)) % 1000&lt;br /&gt;
		if (mod1000 == 0) then&lt;br /&gt;
			suffix = scheme['suffix_1000_'..gender] or scheme.suffix or ''&lt;br /&gt;
		elseif (mod100 == 40) then&lt;br /&gt;
			suffix = scheme['suffix_40_'..gender] or scheme.suffix or ''&lt;br /&gt;
		elseif (mod100 &amp;gt;= 10) and (mod100 &amp;lt;= 19) then&lt;br /&gt;
			suffix = scheme['suffix_'..gender] or scheme.suffix or ''&lt;br /&gt;
		else&lt;br /&gt;
			local mod10 = math.floor(math.abs(value)) % 10&lt;br /&gt;
			suffix = scheme['suffix_'..mod10..'_'..gender] or scheme['suffix_'..mod10] or scheme['suffix_'..gender] or scheme.suffix or ''&lt;br /&gt;
		end&lt;br /&gt;
		output = FormatNum(value, scheme.formatlang or lang) .. Superscript( suffix, scheme.superscript, nosup, period)&lt;br /&gt;
	else&lt;br /&gt;
		output = FormatNum(value, lang)&lt;br /&gt;
	end &lt;br /&gt;
	&lt;br /&gt;
	return output&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- =======================================&lt;br /&gt;
-- === Public Functions ==================&lt;br /&gt;
-- =======================================&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
--[[&lt;br /&gt;
Ordinal&lt;br /&gt;
 &lt;br /&gt;
This function converts an integer value into a numeral followed by ordinal indicator.  The output string might &lt;br /&gt;
contain HTML tags unless you set nosup=y.&lt;br /&gt;
 &lt;br /&gt;
Usage:&lt;br /&gt;
{{#invoke:Ordinal|Ordinal|1=|lang=|style=|gender=|nosup=|debug=}}&lt;br /&gt;
{{#invoke:Ordinal|Ordinal}} - uses the caller's parameters&lt;br /&gt;
 &lt;br /&gt;
Parameters&lt;br /&gt;
    1: Positive integer number. &lt;br /&gt;
    lang: language&lt;br /&gt;
    style: Presentation style. Different options for different languages. In English there is &amp;quot;style=d&amp;quot; adding -d suffixes to all numbers.&lt;br /&gt;
    gender: Gender is used in French and Polish language versions. Genders: m for male, f for female and n for neuter.	&lt;br /&gt;
    nosup: Set nosup=y to display the ordinals without superscript.&lt;br /&gt;
    debug: Set debug=y to output error messages.&lt;br /&gt;
    &lt;br /&gt;
Error Handling:&lt;br /&gt;
   Unless debug=y, any error results in parameter 1 being echoed to the output.  This reproduces the behavior of the original Ordinal template.&lt;br /&gt;
]]&lt;br /&gt;
function p.Ordinal( frame )&lt;br /&gt;
	-- if no argument provided than check parent template/module args&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	if args[1]==nil then&lt;br /&gt;
		args = frame:getParent().args &lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	--  if we don't have a specified language, attempt to use the user's language&lt;br /&gt;
	local lang = args.lang&lt;br /&gt;
	if not lang or lang == '' or not mw.language.isValidCode( lang ) then&lt;br /&gt;
		lang = frame:preprocess('{{int:lang}}')&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local nosup = yesno(args[&amp;quot;nosup&amp;quot;] or '', false) -- nosup can be true or false&lt;br /&gt;
	local debugging = yesno(args[&amp;quot;debug&amp;quot;], false) -- debugging can be nil, true, or false&lt;br /&gt;
&lt;br /&gt;
	-- also enable debugging if debug is unspecified, and &amp;quot;nosup&amp;quot; is false&lt;br /&gt;
	debugging = debugging or ((debugging == nil) and not nosup)&lt;br /&gt;
		&lt;br /&gt;
	local output = p._Ordinal( &lt;br /&gt;
		args[1],  					-- positive integer number&lt;br /&gt;
		lang,						-- language&lt;br /&gt;
		args[&amp;quot;style&amp;quot;],				-- allows to set presentation style&lt;br /&gt;
		args[&amp;quot;gender&amp;quot;], 			-- allows to specify gender (m, f, or n)&lt;br /&gt;
		nosup,						-- set nosup to &amp;quot;y&amp;quot; to suppress superscripts&lt;br /&gt;
		debugging					-- Set debug=y to output error messages&lt;br /&gt;
	)&lt;br /&gt;
	&lt;br /&gt;
	-- Add maintenance category&lt;br /&gt;
	if (i18n.SchemeFromLang[lang] == nil) and debugging then &lt;br /&gt;
		output = output_cat(output, 'Pages with calls to Module Ordinal using an unsupported language')&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return output&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[&lt;br /&gt;
This function will add the appropriate ordinal suffix to a given integer. &lt;br /&gt;
&lt;br /&gt;
Parameters&lt;br /&gt;
	input: Numeral as a positive integer or string.&lt;br /&gt;
	lang: Language code as a string (e.g. 'en', 'de', etc.).&lt;br /&gt;
	style: Presentation style as a string (e.g. 'd', 'roman', etc.).&lt;br /&gt;
	gender: Gender as a string ('m', 'f', 'n').  Use empty string '' to leave gender unspecified.&lt;br /&gt;
	nosup: Boolean, set to true to force the ordinals to display without superscript.&lt;br /&gt;
	debug: Boolean, set to true to output error messages.&lt;br /&gt;
&lt;br /&gt;
Error Handling:&lt;br /&gt;
   Unless debug is true, any error results in value being echoed to the output.&lt;br /&gt;
]]&lt;br /&gt;
function p._Ordinal( input, lang, style, gender, nosup, debugging )	&lt;br /&gt;
	local output = input&lt;br /&gt;
	&lt;br /&gt;
	if input then&lt;br /&gt;
		local value = tonumber(input)&lt;br /&gt;
		if value and (value &amp;gt; 0) then&lt;br /&gt;
		&lt;br /&gt;
			-- Normalize style, the style 'roman year' is an alias for 'roman'&lt;br /&gt;
			style = string.lower(style or '')&lt;br /&gt;
			if style == 'roman year' then&lt;br /&gt;
				style = 'roman'&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			-- Normalize gender parameter&lt;br /&gt;
			gender = string.lower(gender or '')&lt;br /&gt;
			if (gender ~= 'm') and (gender ~= 'f') and (gender ~= 'n') then&lt;br /&gt;
				gender = ''&lt;br /&gt;
			end&lt;br /&gt;
	&lt;br /&gt;
			-- if no language is specified, default to english (caller might want to get user's language)&lt;br /&gt;
			if not lang or lang == '' then&lt;br /&gt;
				lang = 'en';&lt;br /&gt;
			end&lt;br /&gt;
			&lt;br /&gt;
			output = OrdinalCore( value, lang, style, gender, nosup )&lt;br /&gt;
		else&lt;br /&gt;
			if debugging then&lt;br /&gt;
				output = output_error( &amp;quot;not a number&amp;quot;, input )&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		if debugging then&lt;br /&gt;
			output = output_error( &amp;quot;not a number&amp;quot;, '' )&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
		&lt;br /&gt;
	return output&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Zoran</name></author>
	</entry>
</feed>