webuhu
Is there a way to localize numbers in Elixir using all available locales?
Hi all.
I have the following questions. Is there a way to localize numbers in Elixir using all available locales? By all available, I really mean all. Currently I format numbers using Intl.NumberFormat(), but soon I want to format some numbers within a new document format where JS is not an option.
If I am correct, using the great Cldr.Number library I would need to compile the Cldr backend with all locales, which is not an option because of the high compile time.
Are there any other options? Probably later on also for localized formatting of DateTimes…
Thanks a lot.
Most Liked
kip
Yes, the compile time is quite long when using all locales. And the memory requirement is also linear with respect to each locale - perhaps up to 1Mb per locale. So with over 700 locales that can be quite a lot of memory.
However a couple of things to consider:
- While compile time is quite long (in the minutes range), this should only happen once on your development machine, and once in CI after which you would cache the relevant modules. And then once perhaps for production.
- The full list of locales includes a lot of locales that are not in modern use. You could trim the list quite a bit to those in modern use. Of course if you are expecting to support formatting really all (as you noted) then this isn’t much help.
(I’m the author of. most of the ex_cldr_* libraries)
webuhu
That’s what I have expected - that it won’t be simple.
You are really an inspiring fellow human being.
kip
Yes, that’s a fair point indeed.
I am exploring (in my head) how a “version 3” might dynamically load locales. The complication is that number formatting (and some other areas like date time formatting) are actually driven by compile-time code generation. So it’s not as simple as just loading some data. So it’s not simple - and it’s not going to happen right now.
The locale data used to be structured in such a way that determining the “modern use” was straight forward. The data is organized differently now - I will dig into it and report back on a suggestion.







