Module:I18n/ordinal/testcases
Appearance
< Module:I18n | ordinal
Translations used by Module:Ordinal
[සංස්කරණය]Translations are stored in 2 tables:
- p.SchemeFromLang — Table matching individual languages with specific ordinal formatting schemes used by one or more languages. All unlisted languages default to the "period-scheme", i.e. "104." is the ordinal for the value "104". Languages will follow the regular language fallback chain. For example, "de-formal" would fallback to scheme for "de", and only if that does not exist would the "period-scheme" be used.
- p.Scheme — Table of supported schemes. Each scheme has one or more parameters.
- Possible parameters are:
- rules — a value specifying the rules to apply when processing this scheme. Legal values are 'suffix', 'prefix', 'skip-tens', 'suffix-one', 'gendered-suffix', 'gendered-suffix-one', 'mod10-suffix', and 'mod10-gendered-suffix-skip-tens'.
- superscript — if set to true, the ordinal indicator will be superscripted unless the caller specifically suppresses superscription.
- period — if set to true, a period character is output between the numeral and a superscripted suffix
- suffix — default suffix to append to numeral.
- suffix_n — suffix to append if final digit of numeral is n
- suffix_m — suffix to append if gender is male (used by 'gendered-suffix' and 'gendered-suffix-one')
- suffix_f — suffix to append if gender is female (used by 'gendered-suffix' and 'gendered-suffix-one')
- suffix_n — suffix to append if gender is neuter (used by 'gendered-suffix' and 'gendered-suffix-one')
- suffix_1_m — suffix to append if value is one and gender is male (used by 'gendered-suffix-one')
- suffix_1_f — suffix to append if value is one and gender is female (used by 'gendered-suffix-one')
- suffix_1_n — suffix to append if value is one and gender is neuter (used by 'gendered-suffix-one')
- suffix_n_m — suffix to append if value is n and gender is male (used by 'gendered-suffix-n', etc.)
- suffix_n_f — suffix to append if value is n and gender is female (used by 'gendered-suffix-n', etc.)
- suffix_n_n — suffix to append if value is n and gender is neuter (used by 'gendered-suffix-n', etc.)
- prefix — default prefix to prepend to numeral.
- formatlang — overrides the language value used when formatting the numeral
The heart of each ordinal formatting scheme is the rules parameter that specifies the rules to apply when processing a particular scheme. Supported values for rules include:
- 'prefix' — the value in the prefix parameter is written before the numeral as the ordinal indicator. The superscript parameter is ignored by this rule.
- 'suffix' — the value in the suffix parameter is written after the numeral as the ordinal indicator.
- 'suffix-one' — If the numeral is 1 the value in the suffix_1 parameter is written after the numeral as the ordinal indicator, otherwise the value in the suffix parameter is written after the numeral as the ordinal indicator.
- 'mod10-suffix' — the value in the suffix_n parameter is written after the numeral as the ordinal indicator if the final digit of the numeral is n. If the matching suffix_n parameter is not present, the value in the suffix parameter is written after the numeral as the ordinal indicator.
- 'skip-tens' — works the same as 'mod10-suffix', except that numeral values in the range 10..19 don't use the matching suffix_n parameter, they alway use the value in the suffix parameter. This is the scheme used by English and a few other Germanic-related languages.
- 'gendered-suffix' — based on the gender (m, f, n) the matching value in the suffix_gender parameter is written after the numeral as the ordinal indicator. If the matching suffix_gender parameter is not present or no gender is specified by the user, the value in the suffix parameter is written after the numeral as the ordinal indicator. This is the scheme used by the romance languages.
- 'gendered-suffix-one' — A combination of 'gendered-suffix' and 'suffix-one'. If the numeral is 1, then based on the gender (m, f, n) the matching value in the suffix_1_gender parameter is written after the numeral as the ordinal indicator. If the matching suffix_1_gender parameter is not present or no gender is specified by the user, the value in the suffix_1 parameter is written after the numeral as the ordinal indicator. If the numeral is not 1, then based on the gender (m, f, n) the matching value in the suffix_gender parameter is written after the numeral as the ordinal indicator. If the matching suffix_gender parameter is not present or no gender is specified by the user, the value in the suffix parameter is written after the numeral as the ordinal indicator. This is the scheme used by the French language.
- 'gendered-suffix-n' — An expansion of 'gendered-suffix-one'. If the numeral is n (where n <= 9), then based on the gender (m, f, n) the matching value in the suffix_n_gender parameter is written after the numeral as the ordinal indicator. If the matching suffix_n_gender parameter is not present or no gender is specified by the user, the value in the suffix_n parameter is written after the numeral as the ordinal indicator. If that is not present, the value in the matching value in the suffix_gender parameter is written after the numeral as the ordinal indicator. If the numeral is greater than 9, then based on the gender (m, f, n) the matching value in the suffix_gender parameter is written after the numeral as the ordinal indicator. If the matching suffix_gender parameter is not present or no gender is specified by the user, the value in the suffix parameter is written after the numeral as the ordinal indicator. This is the scheme used by the Catalan language.
- 'mod10-gendered-suffix-skip-tens' — A combination of 'skip-tens' and 'gendered-suffix'. The value in the suffix_n_gender parameter is written after the numeral as the ordinal indicator if the final digit of the numeral is n and gender is gender. If the matching suffix_n_gender parameter is not present, or no gender is specified by the user, the value in the matching suffix_n parameter is written after the numeral as the ordinal indicator. If that is not present, the value in the matching value in the suffix_gender parameter is written after the numeral as the ordinal indicator. If that is not present, or no gender is specified by the user, the value in the suffix parameter is written after the numeral as the ordinal indicator. Numeral values in the range 10..19 only use gender. This is the scheme used by the Polish language.
- 'uk-rules' — The Ukrainian rules, processed identically to 'mod10-gendered-suffix-skip-tens' with a special exception for when the final two digits are 40 or the number is a multiple of 1000. If the final two digits are 40, then based on the gender (m, f, n) the matching value in the suffix_40_gender parameter is written after the numeral as the ordinal indicator. If the matching suffix_40_gender parameter is not present or no gender is specified by the user, the value in the suffix parameter is written after the numeral as the ordinal indicator. If the number is a multiple of 1000, then based on the gender (m, f, n) the matching value in the suffix_1000_gender parameter is written after the numeral as the ordinal indicator. If the matching suffix_1000_gender parameter is not present or no gender is specified by the user, the value in the suffix parameter is written after the numeral as the ordinal indicator.
local p = require('Module:UnitTests')
local i18n = require('Module:I18n/ordinal')
function p:test_I18n_ordinal()
self:equals_deep('SchemeFromLang["en"]', i18n.SchemeFromLang["en"], 'en-scheme')
self:equals_deep('SchemeFromLang["de"]', i18n.SchemeFromLang["de"], 'period-scheme')
self:equals_deep('SchemeFromLang["fr"]', i18n.SchemeFromLang["fr"], 'fr-scheme')
self:equals_deep('SchemeFromLang["it"]', i18n.SchemeFromLang["it"], 'romance-scheme')
self:equals_deep('SchemeFromLang["pl"]', i18n.SchemeFromLang["pl"], 'pl-scheme')
self:equals_deep('Scheme["null-scheme"]', i18n.Scheme["null-scheme"],
{})
self:equals_deep('Scheme["period-scheme"]', i18n.Scheme["period-scheme"],
{rules = 'suffix', suffix = '.'})
self:equals_deep('Scheme["en-scheme"]', i18n.Scheme["en-scheme"],
{rules = 'skip-tens', superscript = true, suffix = 'th', suffix_1 = 'st', suffix_2 = 'nd', suffix_3 = 'rd'})
self:equals_deep('Scheme["zh-scheme"]', i18n.Scheme["zh-scheme"],
{rules = 'prefix', prefix = '第'})
self:equals('languages > 20', tablelength(i18n.SchemeFromLang) > 20, true)
self:equals('schemes > 20', tablelength(i18n.Scheme) > 20, true)
end
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
return p