webuhu

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

kip

ex_cldr Core Team

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:

  1. 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.
  2. 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

webuhu

That’s what I have expected - that it won’t be simple.

You are really an inspiring fellow human being.

kip

kip

ex_cldr Core Team

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.

Where Next?

Popular in Questions Top

fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

Other popular topics Top

AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39247 209
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement