CLDRTools, a tool for formatting/shortening numbers, getting plurals etc. (Undocumented!)

So I decided this create a module, this is based on datas of Unicode CLDR, only the following locales are supported:

Supported locale

af, af_ZA, az, az_AZ, id, id_ID, ms, ms_MY, bs, bs_BA, ca, ca_ES, cs, cs_CZ, da, da_DK, de, de_DE, de_CH, de_AT, et, et_EE, en, en_IN, en_GB, en_US, es, es_ES, es_MX, es_US, eu, eu_ES, fil, fil_PH, fr, fr_FR, fr_CA, gl, gl_ES, hr, hr_HR, zu, zu_ZA, is, is_IS, it, it_IT, sw, sw_TZ, lv, lv_LV, lt, lt_LT, hu, hu_HU, nl, nl_NL, nb, nb_NO, uz, uz_UZ, pl, pl_PL, pt, pt_PT, pt, pt_BR, ro, ro_RO, sq, sq_AL, sk, sk_SK, sl, sl_SI, sr, sr_Latn_RS, fi, fi_FI, sv, sv_SE, vi, vi_VN, tr, tr_TR, be, be_BY, bg, bg_BG, ky, ky_KG, kk, kk_KZ, mk, mk_MK, mn, mn_MN, ru, ru_RU, sr, sr_RS, uk, uk_UA, el, el_GR, hy, hy_AM, iw, iw_IL, ur, ur_PK, ar, ar_001, fa, fa_IR, ne, ne_NP, mr, mr_IN, hi, hi_IN, bn, bn_BD, pa, pa_IN, gu, gu_IN, ta, ta_IN, te, te_IN, kn, kn_IN, ml, ml_IN, si, si_LK, th, th_TH, lo, lo_LA, my, my_MM, ka, ka_GE, am, am_ET, km, km_KH, zh, zh_Hans, zh_Hans_CN, zh_Hant, zh_Hant_TW, zh_Hant_HK, ja, ja_JP, ko, ko_KR
and all of its parent and root (obviously)

CLDRTools.rbxm (2,5 MB)

Outdated version

CLDRTools.rbxm (2,5 MB)

This module is undocumented and scrapped as I’m planning to create a better module so this will (likely but not 100 %) be the only version ergo instead of removing it, I thought, why not share it as it have enough features so I made this module for you guys. This is why it’s undocumented but the some parts are similar to Unicode’s CLDR LDML so this could help, here’s the features:

  • Format numbers, e.g. 10000 to 10,000, 1234512.3K
  • Format dates, e.g., 5, 6)5/6/34 (DateTime already have this feature as its builtin, but only for en, en_GB, de, da, and ja locale)
  • Format TimeSpans e.g., 4, 5, 6)3 days
  • Format lists, e.g. {'apples', 'pears', 'oranges'}apples, pears and oranges
  • Format units e.g. 11 inch, 22 inches
  • Getting plurals e.g. .PluralForm(1)one, .PluralForm(2)other
  • etc

(You’ll need the DateTime module from here)
(The formatting number part of this module is incompatible with my previous FormatNumber module, please don’t try to use NumberFormatInfo on this module, it won’t work, DateTimeFormatInfo and TimeSpanFormatInfo on my DateTime module won’t work on this module either).
Update: Fixed the module, testing:

local a ='de', 'DE')
print(CLDR.Numbers.FormatDecimal(a, 2000))
print(CLDR.Numbers.FormatCompactDecimal('en', 'US'), 25125, nil, { 2, 1, 0 }))
print(CLDR.Numbers.FormatPercent('fr', 'FR'), 0.75))
print(CLDR.Units.FormatUnit('en', 'IN'), 123456, 'length-meter', 'long'))
print(CLDR.Units.FormatUnit('en', 'IN'), 1, 'length-inch', 'long'))
print(CLDR.Units.FormatCompoundUnit('ja', 'JP'), 3, 'length-mile', 2, 'duration-second', 'long'))
print(CLDR.Lists.FormatList(a, { a.localeDisplayNames.territories['GB'], a.localeDisplayNames.territories['DE'], a.localeDisplayNames.territories['JP'] }, 'or'))
print(CLDR.Dates.FormatDateTime('da', 'DK'),, 5, 28, 34, 38, 21), 'long'))
print(CLDR.Dates.FormatDate('de', 'DE'),, 1, 31), 'medium'))
print(CLDR.Dates.FormatDate('en', 'US'),, 1, 31), 'medium'))
print(CLDR.Dates.FormatFlexible('en', 'US'),, 2, 5), 'Md'))
print(CLDR.Dates.FormatTime('id', 'ID'),, 1, 1, 14, 15, 16)))
print(("%d%s%02d"):format(1,'id', 'ID').numbers.latn.symbols.timeSeparator, 0))

75 %
1,23,456 metres
1 inch
3 マイル毎2 秒
Vereinigtes Königreich, Deutschland oder Japan
29. maj 1998 kl. 10.38.21 UTC
Jan 31, 2020

What do you think is the most useful part of this module out of these three:

  • Formatting/Shortening numbers (e.g. 1000000 to 1,000,000 and 1500000 to 1.5M)
  • Converting table of strings to human-readable string (e.g. {'a', 'b', 'c', 'd'} to a, b, c and d
  • Pluralisation

0 voters

and what features will you be using on this module:

  • Number & Currencies
  • Dates
  • Units
  • Pluralisation
  • List formatting
  • Getting some of the Unicode CLDR data

0 voters

Are you using for this i18n or just to format numbers/lists/plurals?

  • Yes I’m using this for localisation
  • No, even if there’s only the en (and root) locale, this is enough/overkill for my usage
  • Maybe/Don’t know

0 voters

As this module have a lots of data (2 MB), my upcoming module will you give you an option to select which locale you need so you can save up space, which one of the locales do you need:

  • root only (Not recommended but takes the least amount of space)
  • en_US and its parent (en and root) (Least amount of space suffiicient)
  • en_US, de_DE, ja_JP and all of its parent
  • en_US, en_GB, de_DE, es_ES, zh_Hans_CN, ja_JP and its parent
  • en_US, en_GB, de_DE, es_ES, fr_FR, pt_BR, ja_JP, zh_Hant_TW, zh_Hant_CN and all of its parent
  • All locale Roblox supports
  • The amount of locale supported in the module
  • All of locales supported in CLDR (Most amount of space)
  • Don’t know/Custom
  • I’ll add the locale data (Get prepared to modify the module a lot)

0 voters


If you’re only looking for formatting/shortening integers without being locale-aware, then this module isn’t for you as this module is meant for localising your game.
I suggest this code, if you’re only looking for formatting/shortening integer:

or this module.