# Translations

If you're new to translations then please take a look at our [Twitter thread](https://twitter.com/PetalFramework/status/1496216170084864000) explaining the basics. Also check out:

* the [hex docs for Gettext](https://hexdocs.pm/gettext/Gettext.html)
* a good [blog post](https://phrase.com/blog/posts/i18n-for-phoenix-applications-with-gettext/) explaining Gettext

In a nutshell, you run text that you want translated through the `gettext` function and then add in your translations. These are found in `priv/gettext`. The `.pot` files are auto-generated - you just need to modify the files in the `LC_MESSAGES` folders.

![You should only modify the files in the LC\_MESSAGES folders](https://content.gitbook.com/content/Yos1ARQNZ0mySw9UuAwA/blobs/LjUjFxJj1LO26jAO7KKr/CleanShot%202022-07-08%20at%2007.11.44.png)

We've tried to implement `gettext` throughout the public facing areas of the boilerplate (we may have missed some places - feel free to point them out to us or a PR would be very helpful).&#x20;

### How to add update your pot/po files after adding more gettexts

When you add new `gettext` calls, your translation files won't show them until this command is run:

```
mix gettext.extract --merge
```

Or if you can use our easier-to-remember alias (aliases are defined in the `mix.exs` file):

```
mix update_translations
```

Then go and add your translations to the files in the `LC_MESSAGES` folders for each language.

### How to add/remove languages

Modify the languages in the `confix.exs` file:

{% code title="config.exs" %}

```elixir
config :petal_pro, PetalProWeb.Gettext, allowed_locales: ~w(en fr)

config :petal_pro, :language_options, [
  %{locale: "en", flag: "🇬🇧", label: "English"},
  %{locale: "fr", flag: "🇫🇷", label: "French"}
]
```

{% endcode %}

If you're adding a new language, you'll need to run this (keep in mind `fr` means French - change this to whatever language you're adding - here's [a list of them all](https://www.gnu.org/software/gettext/manual/html_node/Usual-Language-Codes.html)):

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

To delete a language, remove it from the config and delete the corresponding folder in `priv/gettext`.&#x20;
