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.

kip

kip

ex_cldr Core Team

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.

kip

kip

ex_cldr Core Team

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.

Where Next?

Popular in Questions Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
LegitStack
I’m hoping you guys can give me some general advice and perhaps code examples if you’re feeling up to it. I’m very interested in Elixir,...
New
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
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
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement