Skip to main content

RxMetricUnitFormatUtils

Observable formatting, for UI that should follow the player's language. Kept apart from MetricUnitFormatUtils so formatting itself needs no Rx and runs anywhere, servers and specs included.

Functions​

observeFormat​

RxMetricUnitFormatUtils.observeFormat() → Observable<string>

Observes MetricUnitFormatUtils.format in the translator's language: emits again when the player's locale changes or its translations finish streaming in, with English names until then. Numbers follow the translator's locale unless options.locale is given.

local translator = serviceBag:GetService(require("MetricUnitTranslator"))
maid:GiveTask(RxMetricUnitFormatUtils.observeFormat(translator, MetricUnit.new(3, "mile"), {
	unitDisplay = "long",
}):Subscribe(function(text)
	label.Text = text -- "3 miles", "3 millas", "3 Meilen"
end))
Show raw api
{
    "functions": [
        {
            "name": "observeFormat",
            "desc": "Observes [MetricUnitFormatUtils.format] in the translator's language: emits again when the player's locale\nchanges or its translations finish streaming in, with English names until then. Numbers follow the translator's\nlocale unless `options.locale` is given.\n\n```lua\nlocal translator = serviceBag:GetService(require(\"MetricUnitTranslator\"))\nmaid:GiveTask(RxMetricUnitFormatUtils.observeFormat(translator, MetricUnit.new(3, \"mile\"), {\n\tunitDisplay = \"long\",\n}):Subscribe(function(text)\n\tlabel.Text = text -- \"3 miles\", \"3 millas\", \"3 Meilen\"\nend))\n```",
            "params": [
                {
                    "name": "translator",
                    "desc": "[MetricUnitTranslator]",
                    "lua_type": "MetricUnitTranslatorLike"
                },
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "MetricUnit | MetricUnitData"
                },
                {
                    "name": "options",
                    "desc": "",
                    "lua_type": "MetricUnitFormatOptions?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Observable<string>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 38,
                "path": "src/metricutils/src/Shared/Formatting/RxMetricUnitFormatUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "RxMetricUnitFormatUtils",
    "desc": "Observable formatting, for UI that should follow the player's language. Kept apart from\n[MetricUnitFormatUtils] so formatting itself needs no Rx and runs anywhere, servers and specs included.",
    "source": {
        "line": 8,
        "path": "src/metricutils/src/Shared/Formatting/RxMetricUnitFormatUtils.lua"
    }
}