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…
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)
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.
When we talk about long compilation times, how much is long? If it’s in the region of under an hour I think this is not really a problem after it gets cached.
It is about some minutes on fast systems. But it adds up if you count it for each developer machine, for each Elixir / Erlang upgrade, and for library updates.
About 6 minutes for all locales for number formatting on my M1 Max (just timed it).
That’s extremely kind of you to say.
Looks like it’s 401 of the total 725 locales. That needs some additional digging, and I need an API to allow that configuration. Today there is locales: :all configuration. I’ll add :modern, :moderateand:basic` since they also exist as levels.
About 6 minutes for all 725 locales for number formatting on my M1 Max (just timed it).
That’s extremely kind of you to say.
Looks like it’s 401 of the total 725 locales. That needs some additional digging, and I need an API to allow that configuration. Today there is locales: :all configuration. I’ll add :modern, :moderate and :basic since they also exist as levels.
IMO this is irrelevant. I used to work on a project where it took more than 30 minutes to compile app code (on a mac m3 pro) and pretty much the same time to run all tests. After the initial compilation gets cached, it doesn’t matter, it’s extremely rare that you will need to compile from scratch again.