# Gettext basic usage

**URL:** <https://forum.elixirforum.com/t/gettext-basic-usage/30570>\
**Category:** Questions\
**Tags:** phoenix, gettext\
**Created:** [April 12, 2020, 7:27pm UTC](https://forum.elixirforum.com/t/gettext-basic-usage/30570 "2020-04-12T19:27:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asimov](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/asimov/32/4975_2.png) [@Asimov](https://forum.elixirforum.com/u/Asimov)\
**Post date:** [April 12, 2020, 7:27pm UTC](https://forum.elixirforum.com/t/gettext-basic-usage/30570/1 "2020-04-12T19:27:59Z")

</div>

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:

```elixir
mix gettext.extract

```

**3** I was expecting to see:

```elixir
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:

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

```

I found this [post](https://www.freecodecamp.org/news/how-to-perform-localization-in-phoenix-applications-with-gettext-c38bb0f01bef/) where they suggest to run this:

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

```

So I did (is this correct?):

```elixir
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!

---

<div class="post-metadata">

**Author:** ![sfusato](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sfusato/32/11569_2.png) [@sfusato](https://forum.elixirforum.com/u/sfusato)\
**Post date:** [April 12, 2020, 8:35pm UTC](https://forum.elixirforum.com/t/gettext-basic-usage/30570/2 "2020-04-12T20:35:41Z")

</div>

Check the [workflow](https://github.com/elixir-gettext/gettext#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.

---

<div class="post-metadata">

**Author:** ![Asimov](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/asimov/32/4975_2.png) [@Asimov](https://forum.elixirforum.com/u/Asimov)\
**Post date:** [April 13, 2020, 4:43pm UTC](https://forum.elixirforum.com/t/gettext-basic-usage/30570/3 "2020-04-13T16:43:13Z")

</div>

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](https://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html) 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:

```elixir
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

---

<div class="post-metadata">

**Author:** ![sfusato](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sfusato/32/11569_2.png) [@sfusato](https://forum.elixirforum.com/u/sfusato)\
**Post date:** [April 13, 2020, 5:03pm UTC](https://forum.elixirforum.com/t/gettext-basic-usage/30570/4 "2020-04-13T17:03:54Z")

</div>

From where did you got the config setting?

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

I’m asking because I’m not seeing it in the [documentation](https://hexdocs.pm/gettext/Gettext.html#module-backend-configuration). Perhaps that’s what created your issues?

For a Phoenix project, you don’t need to add any configuration as it comes pre-configured in `myapp_web/gettext.ex`

---

<div class="post-metadata">

**Author:** ![Asimov](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/asimov/32/4975_2.png) [@Asimov](https://forum.elixirforum.com/u/Asimov)\
**Post date:** [April 13, 2020, 6:20pm UTC](https://forum.elixirforum.com/t/gettext-basic-usage/30570/5 "2020-04-13T18:20:29Z")

</div>

From [here](https://www.freecodecamp.org/news/how-to-perform-localization-in-phoenix-applications-with-gettext-c38bb0f01bef/)
