모듈:Ordinal-cd

--  

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.

Authors and maintainers:- User:RP88


-- ===================================**
-- === Dependencies ==================**
-- ===================================**
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 formatnum  = require('Module:Formatnum')           -- number formatting
-- ===================================**
-- === Private Functions =============**
-- ===================================**
--
Helper function to generate superscripted content
local function Superscript( str, superscript, nosup, period )
	if superscript and (not nosup) and (str ~= ) then
		return period ..  .. str .. 
	else
		return str
	end
end
	
--
Helper function to call Formatnum.
local function FormatNum( value, lang )
	if lang == 'roman' then
		return require("Module:Roman-cd")._Numeral(value)
	else
		return formatnum.formatNum(value, lang)
	end
end
	
--
Helper function to add append a category to a message.
local function output_cat( message, category )
return message .. 
end
--
Helper function to handle error messages.
local function output_error( error_str, value )
	error_str =  .. value .. 
return output_cat(error_str, 'Errors reported by Module Ordinal');
end
--
This function is the core functionality for adding the appropriate ordinal suffix to a given integer.
local function OrdinalCore( value, lang, style, gender, nosup )	
	-- Just in case someone breaks the internationalization code, fix the english scheme
	if i18n.SchemeFromLang'en' == nil then
		i18n.SchemeFromLang'en' = 'en-scheme'
	end	
	if i18n.Scheme'en-scheme' == nil then
		i18n.Scheme'en-scheme' = {rules = 'skip-tens', superscript = true, suffix = 'th', suffix_1 = 'st', suffix_2 = 'nd', suffix_3 = 'rd'}
	end
	
	-- Add the default scheme (i.e. ".")
	if i18n.SchemeFromLang'default' == nil then
		i18n.SchemeFromLang'default' = 'period-scheme'
	end	
	if i18n.Scheme'period-scheme' == nil then
		i18n.Scheme'period-scheme' = {rules = 'suffix', suffix = '.'}
	end
		
	-- which scheme should we use to format the ordinal value? 
	-- Use Fallback module to handle languages groups that map to a supported language
	local schemeSpecifier = LangSwitch._langSwitch(i18n.SchemeFromLang, lang)
	
	-- Look up scheme based on scheme specifier (and possibly style)
	local scheme = i18n.SchemeschemeSpecifier .. '/' .. style or i18n.SchemeschemeSpecifier
	
	-- process scheme by applying rules identified by Scheme
	local output = 
	local period = (scheme.period and '.') or 
	local rules = scheme.rules
	if rules == 'skip-tens' then
		local suffix
		local mod100 = math.floor(math.abs(value)) % 100
		if (mod100 >= 10) and (mod100 = 10) and (mod100 = 10) and (mod100  0) then
		
			-- Normalize style, the style 'roman year' is an alias for 'roman'
			style = string.lower(style or )
			if style == 'roman year' then
				style = 'roman'
			end
			
			-- Normalize gender parameter
			gender = string.lower(gender or )
			if (gender ~= 'm') and (gender ~= 'f') and (gender ~= 'n') then
				gender = 
			end
	
			-- if no language is specified, default to english (caller might want to get user's language)
			if not lang or lang ==  then
				lang = 'en';
			end
			
			output = OrdinalCore( value, lang, style, gender, nosup )
		else
			if debugging then
				output = output_error( "not a number", input )
			end
		end
	else
		if debugging then
			output = output_error( "not a number",  )
		end
	end
		
	return output
end
return p