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:
https://github.com/elixir-gettext/gettext/blob/main/lib/mix/tasks/gettext.extract.ex#L106-L126

Most Liked

kip

kip

ex_cldr Core Team

I’ve not heard of any issues using this approach (no issues logged in GitHub and I’ve seen no other references here on the forum or slack). And I can’t see any particular reason is shouldn’t work either than if you also configure the :gettext option in your CLDR backend module. In that case you would probably have to force compile the local dependency to pick up any gettext configuration changes.

Where Next?

Popular in Questions Top

New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
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
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
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