MetricUnitTranslator
Translated unit names and symbols, streamed to each client one locale at a time. A JSONTranslator over the
<locale>.json files beside this module, so a player downloads only the English source and their own language.
Get it from the ServiceBag and pass it to MetricUnit.format or RxMetricUnitFormatUtils.observeFormat.
local translator = serviceBag:GetService(require("MetricUnitTranslator"))
maid:GiveTask(RxMetricUnitFormatUtils.observeFormat(translator, MetricUnit.new(3, "mile"):ToUSCustomary(), {
unitDisplay = "long",
}):Subscribe(function(text)
label.Text = text -- "3 miles", "3 millas", "3 Meilen", "3 мили"
end))
Seventeen languages ship, the ones NumberLocalizationUtils formats numbers for: English, Spanish, French,
German, Portuguese, Italian, Russian, Polish, Turkish, Indonesian, Vietnamese, Thai, Arabic, Simplified and
Traditional Chinese, Japanese and Korean. Every file has every key:
-
units.<unitId>.long.<category>andunits.<unitId>.short.<category>for each of CLDR's plural categories (zero,one,two,few,many,other), picked by PluralCategoryUtils.getPluralCategory. per.<timeUnit>.longandper.<timeUnit>.short, where{n}is the whole "number unit" before them.
{n} is the number, written for the locale. The files are maintained by hand. English matches
MetricUnitDefinitions, which a spec checks; the other languages come from Unicode CLDR's unit patterns (see the
Unicode notice in this module's source). A no-break space joins a number to its unit.