RealVidy

RealVidy

Gettext custom plural_forms module not working

Hi, using gettext, I’m trying to define a locale variant to handle formal vs informal french (so “fr” vs “fr@formal” in my case).

I tried to add a plural module to my app, as specified in the docs, but it seems to completely ignore it.

defmodule MyApp.Plural do
  @behaviour Gettext.Plural

  # Fallback to Gettext.Plural
  def nplurals("fr@formal"), do: 2
  def nplurals(locale), do: Gettext.Plural.nplurals(locale)

  def plural("fr@formal", 0), do: 0
  def plural("fr@formal", 1), do: 1

  def plural(locale, n) do
    Gettext.Plural.plural(locale, n)
  end
end

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

Running mix gettext.merge priv/gettext --locale fr@formal gives me

** (Gettext.Plural.UnknownLocaleError) unknown locale “fr@formal”. If this is a locale you need to handle,
consider using a custom pluralizer module instead of the default
Gettext.Plural. You can read more about this on the Gettext docs at
Gettext.Plural — gettext v1.0.2

What am I missing?

First Post!

kip

kip

ex_cldr Core Team

I suspect you may need to run mix gettext.merge priv/gettext --locale fr@formal before you configure your Gettext backend with your plurals module.

Last Post!

c4710n

c4710n

quoted from docs of gettext:

Task such as mix gettext.merge use the plural backend configured under the :gettext application, so in general the global configuration approach is preferred.

Because of that, use the global configuration:

# For example, in config/config.exs
config :gettext, :plural_forms, MyApp.Plural

Instead of the configuration for a specific backend module:

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

Then, the problem should be solved.

Where Next?

Popular in Questions Top

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
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
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44265 214
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement