MrYawe

MrYawe

Avoiding ex_cldr backend module recompilation

The problem

Every time we run mix gettext.extract it recompiles our app to extract gettext messages (that’s normal) but it also recompiles the cldr backend module which is slow to compiles (more than 10s).

Can we do something to avoid cldr backend module recompilation? I don’t think this should be needed here.

How to reproduce

We can easily reproduce this with a new phoenix app and the last elixir version (1.16.2):

mix phx.new my_app --database sqlite3

Add these deps:

{:ex_cldr, "~> 2.38"},
{:ex_cldr_messages, "~> 1.0"}

Add a backend module:

defmodule MyApp.Cldr do
  use Cldr,
    locales: ["en", "de", "es", "fr", "it", "ja", "ko", "nl", "pt", "zh"],
    default_locale: "en",
    providers: [Cldr.Message]
end

Add this configuration in config.exs:

config :ex_cldr,
  default_backend: MyApp.Cldr

And now every time you run mix gettext.extract you will see:

Compiling 16 files (.ex)
Generating MyApp.Cldr for 11 locales named [:de, :en, :es, :fr, :it, ...] with a default locale named :en

What I’ve tested so far

I know that deps are only compiled once so I’ve made a small experiment: instead of putting our cldr backend module in our app, I’ve put it as local deps.

mix.exs:

{:my_app_cldr, path: "./my_app_cldr"}

config.exs:

config :ex_cldr,
  default_backend: MyAppCldr

Then in the my_app_cldr subfolder, generated using mix new my_app_cldr:

mix.exs:

defp deps do
  [
    {:ex_cldr, "~> 2.38"},
    {:ex_cldr_messages, "~> 1.0"},
  ]
end
defmodule MyAppCldr do
  use Cldr,
    locales: ["en", "de", "es", "fr", "it", "ja", "ko", "nl", "pt", "zh"],
    default_locale: "en",
    providers: [Cldr.Message]
end

And.. it seems to work :smile:
MyAppCldr is only compiled once as a deps and then I can use this module in my app but I don’t know if it’s recommended to use cldr this way.

First Post!

03juan

03juan

Long story short: no, it’s doing a full recompilation of your app:

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
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
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

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
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

We're in Beta

About us Mission Statement