بۆ ناوەڕۆک بازبدە

مۆدیوول:Ordinal

لە ئینسایکڵۆپیدیای ئازادی ویکیپیدیاوە
بەڵگەدارکردنی مۆدیوول[دروست بکە]
--[[  
 
This template will add the appropriate ordinal suffix to a given integer.
 
Please do not modify this code without applying the changes first at
Module:Ordinal/sandbox and testing at Module:Ordinal/sandbox/testcases and
Module talk:Ordinal/sandbox/testcases.
 
]]

local p = {}

local yesno     = require('Module:Yesno') -- boolean value interpretation

local convert     = require('Module:Numeral converter').convert -- Perso-Arabic numerals interpretation

--[[
This function converts an integer value into a numeral followed by ordinal indicator.
The output string might contain HTML tags.
 
Usage:
{{#invoke:Ordinal|ordinal|1=|2=|sup=}}
{{#invoke:Ordinal|ordinal}} - uses the caller's parameters
 
Parameters
    1: Any number or string.
    2: Set to "مین" if the module should display "ەمین" and "یەمین" instead of "ەم" and "یەم".
    sup: Set to yes/no to toggle superscript ordinal suffix.
]]
function p.ordinal(frame)
	local args = frame.args
	local suffix = "ەم"
    if args[1] == nil then
        args = frame:getParent().args
    end
    if args[1] == nil then
    	args[1] = "{{{1}}}"
    end
    return p._ordinal(args[1], (args[2] == 'مین'), yesno(args.sup))
end

function p._ordinal(n, d, sup)
	local x = tonumber(mw.ustring.match(convert("en",n), "(%d*)%W*$"))
	local suffix = "ەم"
	-- If tonumber(n) worked:
	if x then
		local mod10 = math.abs(x) % 10
		local mod100 = math.abs(x) % 100

        if mod10 == 3 or mod10 == 9 or mod100 == 10 or mod100 == 11 or mod100 == 12 or mod100 == 13 or mod100 == 14 or mod100 == 15 or mod100 == 16 or mod100 == 17 or mod100 == 18 or mod100 == 19 or mod100 == 23 or mod100 == 29 or mod100 == 30 or mod100 == 33 or mod100 == 39 or mod100 == 43 or mod100 == 49 or mod100 == 50 or mod100 == 53 or mod100 == 59 or mod100 == 63 or mod100 == 69 or mod100 == 70 or mod100 == 73 or mod100 == 79 or mod100 == 80 or mod100 == 83 or mod100 == 89 or mod100 == 93 or mod100 == 99 then
			if d then suffix = "یەمین" else suffix = "یەم" end

	    elseif d then
			suffix = "ەمین"
		end
	end
	if sup then
		suffix = "<sup>" .. suffix .. "</sup>"
	end
	return n .. suffix
end

return p