Skip to main content

MetricUnitFallbackStrings

English unit names for MetricUnitFormatUtils when no translator is given. They need no translator, so specs, servers and anything formatting before a translator loads always get readable text. Translated names stream to clients through MetricUnitTranslator, a JSONTranslator holding the same keys.

Lookups resolve through ResolveLocaleUtils, so en-us lands on American English and en-au on Commonwealth English. Without a translator, short phrases are the symbols in MetricUnitDefinitions; with one, they are the player's language's (5 км, 5公里). A no-break space joins a number to its unit either way.

Types​

UnitPhrase​

type UnitPhrase = {
one: string,
other: string
} | (
amount: number,
numberText: string
) → string

A unit phrase with %s for the already formatted number: a singular and plural pair, or a function of the rounded amount and the formatted number for languages with more plural forms.

UnitNames​

interface UnitNames {
short: UnitPhrase
long: UnitPhrase
}

The short and long phrase for one unit, such as "%s km" and "%s kilometers".

UnitStrings​

type UnitStrings = {[UnitId]: UnitNames}

UnitNames for every unit written by name, keyed by unit id: every unit MetricUnitDefinitions gives names. Time units are written with TimeLocalizationUtils' duration words instead, and bare rates with PerStrings.

PerNames​

interface PerNames {
short: string
long: string
}

How to write something per a time unit, with %s for the numerator already written: "%s/h" and "%s per hour".

PerStrings​

interface PerStrings {
second: PerNames
minute: PerNames
hour: PerNames
day: PerNames
week: PerNames
month: PerNames
year: PerNames
}

PerNames for every time unit a rate can be written per.

UnitStringOverrides​

type UnitStringOverrides = {[string]: {
short: UnitPhrase?,
}}

Unit phrases a caller passes to override a locale's, keyed by unit id: { kilometer = { short = "%s klicks" } }.

PerStringOverrides​

type PerStringOverrides = {[string]: {
short: string?,
long: string?
}}

Per phrases a caller passes to override a locale's, keyed by time unit id.

UnitLocale​

interface UnitLocale {
units: UnitStrings
}

Everything one locale needs.

Functions​

toCommonwealthSpelling​

MetricUnitFallbackStrings.toCommonwealthSpelling(text: string) → string

text in Commonwealth English spelling: metre for meter, litre for liter, tonne for metric ton.

hasLocale​

MetricUnitFallbackStrings.hasLocale(locale: string?) → boolean

Whether a locale has its own unit names here, directly or through a locale of the same language.

getLocale​

MetricUnitFallbackStrings.getLocale(locale: string?) → UnitLocale

Returns the read-only UnitLocale for a locale, defaulting to American English. Warns once per unknown locale.

getUnitNames​

MetricUnitFallbackStrings.getUnitNames(
locale: string?,
) → UnitNames

The UnitNames of unit in a locale: the locale's own, or, for a unit a game's own MetricUnitSystem declares, its English names and symbol from its definition.

getUnitStringsForLocale​

MetricUnitFallbackStrings.getUnitStringsForLocale(locale: string?) → UnitStrings

Returns the read-only UnitStrings for a locale, defaulting to American English. Each unit's names are built the first time they are read.

getPerStringsForLocale​

MetricUnitFallbackStrings.getPerStringsForLocale(locale: string?) → PerStrings

Returns the read-only PerStrings for a locale, defaulting to American English.

Show raw api
{
    "functions": [
        {
            "name": "toCommonwealthSpelling",
            "desc": "`text` in Commonwealth English spelling: metre for meter, litre for liter, tonne for metric ton.",
            "params": [
                {
                    "name": "text",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 134,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "hasLocale",
            "desc": "Whether a locale has its own unit names here, directly or through a locale of the same language.",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 218,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "getLocale",
            "desc": "Returns the read-only [UnitLocale] for a locale, defaulting to American English. Warns once per unknown locale.",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "UnitLocale"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 228,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "getUnitNames",
            "desc": "The [UnitNames] of `unit` in a locale: the locale's own, or, for a unit a game's own [MetricUnitSystem] declares,\nits English names and symbol from its definition.",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                },
                {
                    "name": "unit",
                    "desc": "",
                    "lua_type": "UnitDefinition"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "UnitNames"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 256,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "getUnitStringsForLocale",
            "desc": "Returns the read-only [UnitStrings] for a locale, defaulting to American English. Each unit's names are built the\nfirst time they are read.",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "UnitStrings"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 275,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "getPerStringsForLocale",
            "desc": "Returns the read-only [PerStrings] for a locale, defaulting to American English.",
            "params": [
                {
                    "name": "locale",
                    "desc": "",
                    "lua_type": "string?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "PerStrings"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 285,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "UnitPhrase",
            "desc": "A unit phrase with `%s` for the already formatted number: a singular and plural pair, or a function of the\nrounded amount and the formatted number for languages with more plural forms.",
            "lua_type": "{ one: string, other: string } | (amount: number, numberText: string) -> string",
            "source": {
                "line": 30,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "UnitNames",
            "desc": "The short and long phrase for one unit, such as `\"%s km\"` and `\"%s kilometers\"`.",
            "fields": [
                {
                    "name": "short",
                    "lua_type": "UnitPhrase",
                    "desc": ""
                },
                {
                    "name": "long",
                    "lua_type": "UnitPhrase",
                    "desc": ""
                }
            ],
            "source": {
                "line": 40,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "UnitStrings",
            "desc": "[UnitNames] for every unit written by name, keyed by unit id: every unit [MetricUnitDefinitions] gives `names`. Time\nunits are written with [TimeLocalizationUtils]' duration words instead, and bare rates with [PerStrings].",
            "lua_type": "{ [UnitId]: UnitNames }",
            "source": {
                "line": 49,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "PerNames",
            "desc": "How to write something per a time unit, with `%s` for the numerator already written: `\"%s/h\"` and\n`\"%s per hour\"`.",
            "fields": [
                {
                    "name": "short",
                    "lua_type": "string",
                    "desc": ""
                },
                {
                    "name": "long",
                    "lua_type": "string",
                    "desc": ""
                }
            ],
            "source": {
                "line": 60,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "PerStrings",
            "desc": "[PerNames] for every time unit a rate can be written per.",
            "fields": [
                {
                    "name": "second",
                    "lua_type": "PerNames",
                    "desc": ""
                },
                {
                    "name": "minute",
                    "lua_type": "PerNames",
                    "desc": ""
                },
                {
                    "name": "hour",
                    "lua_type": "PerNames",
                    "desc": ""
                },
                {
                    "name": "day",
                    "lua_type": "PerNames",
                    "desc": ""
                },
                {
                    "name": "week",
                    "lua_type": "PerNames",
                    "desc": ""
                },
                {
                    "name": "month",
                    "lua_type": "PerNames",
                    "desc": ""
                },
                {
                    "name": "year",
                    "lua_type": "PerNames",
                    "desc": ""
                }
            ],
            "source": {
                "line": 75,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "UnitStringOverrides",
            "desc": "Unit phrases a caller passes to override a locale's, keyed by unit id: `{ kilometer = { short = \"%s klicks\" } }`.",
            "lua_type": "{ [string]: { short: UnitPhrase?, long: UnitPhrase? } }",
            "source": {
                "line": 91,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "PerStringOverrides",
            "desc": "Per phrases a caller passes to override a locale's, keyed by time unit id.",
            "lua_type": "{ [string]: { short: string?, long: string? } }",
            "source": {
                "line": 99,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        },
        {
            "name": "UnitLocale",
            "desc": "Everything one locale needs.",
            "fields": [
                {
                    "name": "units",
                    "lua_type": "UnitStrings",
                    "desc": ""
                },
                {
                    "name": "per",
                    "lua_type": "PerStrings",
                    "desc": ""
                }
            ],
            "source": {
                "line": 109,
                "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
            }
        }
    ],
    "name": "MetricUnitFallbackStrings",
    "desc": "English unit names for [MetricUnitFormatUtils] when no translator is given. They need no translator, so specs,\nservers and anything formatting before a translator loads always get readable text. Translated names stream to clients through [MetricUnitTranslator], a\n`JSONTranslator` holding the same keys.\n\nLookups resolve through [ResolveLocaleUtils], so `en-us` lands on American English and `en-au` on Commonwealth\nEnglish. Without a translator, short phrases are the symbols in [MetricUnitDefinitions]; with one, they are the player's language's\n(`5 км`, `5公里`). A no-break space joins a number to its unit either way.",
    "source": {
        "line": 13,
        "path": "src/metricutils/src/Shared/Localization/MetricUnitFallbackStrings.lua"
    }
}