Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

// request.cf · coarse context

A page that knows where it met you.

Only coarse request metadata is shown. This demo does not display or persist visitor IP addresses.

Country
US
Cloudflare location
CMH
Connection
HTTP/2
Language
Not provided

Ray ID: a221766a2f8a22ce

Jump to content

Module:Sandbox/Batternut/Ordinal

From Wikipedia, the free encyclopedia
-- vim: set noexpandtab ft=lua ts=4 sw=4:
require('strict')

local o = {}
local debug = false

--[[
makeOrdinal

This function returns an ordinal string for the target number.

Usage:
{{#invoke:Ordinal|makeOrdinal|target_num|}}

Parameters
    1: The string whose length to report
    2: the language code

If invoked using named parameters, Mediawiki will automatically remove any leading or
trailing whitespace from the target string.  
]]
function o.makeOrdinal( target_num, langcode )
	if langcode == 'fr' then
		if target_num == 1 then
	    	return target_num .. 'er'
    	else
			return target_num .. 'e'
		end
	elseif langcode == 'en' then
		if target_num == 11 or target_num == 12 or target_num == 13 then
	    	return target_num .. 'th'
		elseif target_num % 10 == 1 then
			return target_num .. 'st'
		elseif target_num % 10 == 2 then
			return target_num .. 'nd'
		elseif target_num % 10 == 3 then
			return target_num .. 'rd'
		else
			return target_num .. 'th'
		end
	else
		return target_num .. '.'
	end
end

return o