What is a gettext backend?

The gettext library allows you to have multiple “backends” (as they keep mentioning in the docs) and provides functions that apply only for specific backends.

E.g. :
get_locale() / get_locale(backend)
put_locale(locale) / put_locale(backend, locale)
etc.

I notice that gettext/3 only works with a given backend though.

What is meant here by a backend? In which cases would you have multiple “backends” configured differently?

Backend means the implementation of gettext. You’ll know once read this :slightly_smiling_face: https://en.m.wikipedia.org/wiki/Gettext

The module that implements the backend behaviour, usually by using the Gettext module.

defmodule MyApp.Gettext do
  use Gettext, otp_app: :my_app
end

In which cases would you have multiple “backends” configured differently?

Perhaps when different apps / parts of the app need different translations, similar to when you’d use multiple ecto repos.

2 Likes