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
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
Task such as
mix gettext.mergeuse the plural backend configured under the:gettextapplication, 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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









