Skip to main content

NumberLocalizationOrdinalUtils

Localizes ordinal numbers, for example 22nd in English, 22e in French, 22. in German or 第22 in Chinese. Rules are keyed by language subtag and resolved through ResolveLocaleUtils, so regional variants such as en-gb or es-mx land on their language's rule. Locales without a rule fall back to English with a warning.

To add a language, add one entry to ORDINAL_RULES. Every field is required.

Types​

OrdinalRule​

interface OrdinalRule {
prefix: string
suffix: (number) → string
}

How a language writes an ordinal: prefix .. number .. suffix(number).

Functions​

localize​

NumberLocalizationOrdinalUtils.localize(
number: number,
locale: string
) → string

Returns the localized ordinal form of a whole number.

print(NumberLocalizationOrdinalUtils.localize(22, "en-us")) --> 22nd
print(NumberLocalizationOrdinalUtils.localize(1, "fr-fr")) --> 1er
print(NumberLocalizationOrdinalUtils.localize(22, "zh-cn")) --> 第22

getSuffix​

NumberLocalizationOrdinalUtils.getSuffix(
number: number,
locale: string
) → string

Returns only the part of the localized ordinal that follows the number, for example nd for 22 in English or . in German. Languages that mark ordinals with a prefix (Chinese, Japanese, Korean, Indonesian, Vietnamese, Thai) have an empty suffix; use NumberLocalizationOrdinalUtils.localize for the whole form.

Show raw api
{
    "functions": [
        {
            "name": "localize",
            "desc": "Returns the localized ordinal form of a whole number.\n\n```lua\nprint(NumberLocalizationOrdinalUtils.localize(22, \"en-us\")) --> 22nd\nprint(NumberLocalizationOrdinalUtils.localize(1, \"fr-fr\")) --> 1er\nprint(NumberLocalizationOrdinalUtils.localize(22, \"zh-cn\")) --> 第22\n```",
            "params": [
                {
                    "name": "number",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 139,
                "path": "src/clienttranslator/src/Shared/Numbers/NumberLocalizationOrdinalUtils.lua"
            }
        },
        {
            "name": "getSuffix",
            "desc": "Returns only the part of the localized ordinal that follows the number, for example `nd` for\n22 in English or `.` in German. Languages that mark ordinals with a prefix (Chinese, Japanese,\nKorean, Indonesian, Vietnamese, Thai) have an empty suffix; use\n[NumberLocalizationOrdinalUtils.localize] for the whole form.",
            "params": [
                {
                    "name": "number",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 152,
                "path": "src/clienttranslator/src/Shared/Numbers/NumberLocalizationOrdinalUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "OrdinalRule",
            "desc": "How a language writes an ordinal: `prefix .. number .. suffix(number)`.",
            "fields": [
                {
                    "name": "prefix",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "suffix",
                    "lua_type": "(number) -> string",
                    "desc": ""
                }
            ],
            "source": {
                "line": 29,
                "path": "src/clienttranslator/src/Shared/Numbers/NumberLocalizationOrdinalUtils.lua"
            }
        }
    ],
    "name": "NumberLocalizationOrdinalUtils",
    "desc": "Localizes ordinal numbers, for example `22nd` in English, `22e` in French, `22.` in German or\n`第22` in Chinese. Rules are keyed by language subtag and resolved through [ResolveLocaleUtils],\nso regional variants such as `en-gb` or `es-mx` land on their language's rule. Locales without\na rule fall back to English with a warning.\n\nTo add a language, add one entry to `ORDINAL_RULES`. Every field is required.",
    "source": {
        "line": 12,
        "path": "src/clienttranslator/src/Shared/Numbers/NumberLocalizationOrdinalUtils.lua"
    }
}