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
to10,000
,12345
→12.3K
- Format dates, e.g.
DateTime.new(1234, 5, 6)
→5/6/34
(DateTime already have this feature as its builtin, but only foren, en_GB, de, da, and ja
locale) - Format TimeSpans e.g.
TimeSpan.new(3, 4, 5, 6)
→3 days
- Format lists, e.g.
{'apples', 'pears', 'oranges'}
→apples, pears and oranges
- Format units e.g.
1
→1 inch
,2
→2 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 = CLDR.Locale.new('de', 'DE')
print(CLDR.Numbers.FormatDecimal(a, 2000))
print(CLDR.Numbers.FormatCompactDecimal(CLDR.Locale.new('en', 'US'), 25125, nil, { 2, 1, 0 }))
print(CLDR.Numbers.FormatPercent(CLDR.Locale.new('fr', 'FR'), 0.75))
print(CLDR.Units.FormatUnit(CLDR.Locale.new('en', 'IN'), 123456, 'length-meter', 'long'))
print(CLDR.Units.FormatUnit(CLDR.Locale.new('en', 'IN'), 1, 'length-inch', 'long'))
print(CLDR.Units.FormatCompoundUnit(CLDR.Locale.new('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(CLDR.Locale.new('da', 'DK'), DateTime.DateTime.new(1998, 5, 28, 34, 38, 21), 'long'))
print(CLDR.Dates.FormatDate(CLDR.Locale.new('de', 'DE'), DateTime.DateTime.new(2020, 1, 31), 'medium'))
print(CLDR.Dates.FormatDate(CLDR.Locale.new('en', 'US'), DateTime.DateTime.new(2020, 1, 31), 'medium'))
print(CLDR.Dates.FormatFlexible(CLDR.Locale.new('en', 'US'), DateTime.DateTime.new(2020, 2, 5), 'Md'))
print(CLDR.Dates.FormatTime(CLDR.Locale.new('id', 'ID'), DateTime.DateTime.new(1, 1, 1, 14, 15, 16)))
print(("%d%s%02d"):format(1, CLDR.Locale.new('id', 'ID').numbers.latn.symbols.timeSeparator, 0))
2.000
25.1K
75 %
1,23,456 metres
1 inch
3 マイル毎2 秒
Vereinigtes Königreich, Deutschland oder Japan
29. maj 1998 kl. 10.38.21 UTC
31.01.2020
Jan 31, 2020
2/5
14.15.16
1.00
(Survey)
What do you think is the most useful part of this module out of these three:
- Formatting/Shortening numbers (e.g.
1000000
to1,000,000
and1500000
to1.5M
) - Converting table of strings to human-readable string (e.g.
{'a', 'b', 'c', 'd'}
toa, 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
(androot
) 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
androot
) (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