Asimov

Asimov

Gettext basic usage

Hi all,

I am trying to use Gettext to enable English US, French Canada and Spanish Spain in my Phoenix web app. I had never used Gettext before but based on the documentation and a couple of blogs I believe this is what I had to do:

1 Add this line to my config.exs:
config :myApp, MyAppWeb.Gettext, locales: ~w(en_US fr_CA es_ES).

2 Then I had to run:

mix gettext.extract

3 I was expecting to see:

priv/gettext
└─ en_US
| └─ LC_MESSAGES
| └─ errors.po
└─ default.pot
└─ errors.pot
└─ fr_CA
| └─ LC_MESSAGES
| └─ errors.po
└─ default.pot
└─ errors.pot
└─ es_ES
| └─ LC_MESSAGES
| └─ errors.po
└─ default.pot
└─ errors.pot

However all I get is:

└─ en
| └─ LC_MESSAGES
| └─ errors.po
└─ default.pot
└─ errors.pot

I found this post where they suggest to run this:

mix gettext.extract mix gettext.merge priv/gettext mix gettext.merge priv/gettext --locale LOCALE_CODE

So I did (is this correct?):

mix gettext.extract mix gettext.merge priv/gettext mix gettext.merge priv/gettext --locale en_US
mix gettext.extract mix gettext.merge priv/gettext mix gettext.merge priv/gettext --locale fr_CA
mix gettext.extract mix gettext.merge priv/gettext mix gettext.merge priv/gettext --locale es_ES

But while it does not fail, I do not see any new file/folder being created under the priv folder. Am I supposed to add them up manually? I do not mind doing it but I want to make sure I do not break any integrity while doing it.

The main question would be: what I am doing, is that the correct way to start using Gettext? If not, can you please put me in the right track?

As always, thanks very much for any feedback!

Marked As Solved

Asimov

Asimov

Thank you @sfusato for the reply. It is very much appreciated. So, at the end I had to make a couple of changes:

1 In config.exs:

config :myApp, MyAppWeb.Gettext, locales: ~w(en fr es)

Not sure why but it seems that ll_CC format may cause issues. For what I understood in gettext doc that was the suggested format. But I could not make it work, so I just made my life simpler using only the language code without the country.

2 Then the command that did it for me was:

mix gettext.merge priv/gettext --locale fr
mix gettext.merge priv/gettext --locale es

3 After that a simple (as mentioned by @sfusato mix gettext.extract --merge updates any change in the pages.

I am leaving it here in case it helps to anyone else in the future.

Thanks

Also Liked

sfusato

sfusato

Check the workflow as described on Gettext github readme.

You would need to run the command with the specific locale flag once. Afterwards, just running mix gettext.extract --merge will extract and merge all the locale.

Last Post!

Asimov

Asimov

From here

Where Next?

Popular in Questions Top

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
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
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
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
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
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

We're in Beta

About us Mission Statement