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?
Trending in Questions
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Hello !
We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
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
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










First 10 of 12 Posts!
kip
I suspect you may need to run
mix gettext.merge priv/gettext --locale fr@formalbefore you configure yourGettextbackend with your plurals module.RealVidy
Thanks for your answer Kip, it seems that this doesn’t help unfortunately.
I removed
plural_forms: MyApp.Pluralinuse Gettext, otp_app: :my_app, plural_forms: MyApp.Pluraland ran themix gettext.merge priv/gettext --locale fr@formalcommand. I get the same error.kip
Sorry to hear that. I just created a new app with a gettext backend and no plurals module. And then:
It seemed to be fine creating the locale files. Afraid I’m out of ideas as this stage.
RealVidy
Something must be wrong on my end then. Can I ask how you create your new app? I ran into the same issue with a phoenix app I created with a simple
mix phx.new test-appkip
I just just
mix new my_app(ie not Phoenix) although that really shouldn’t matter.eriklindgren
Did you ever find a solution to this @RealVidy? I have the exact same issue.
RealVidy
Unfortunately, no
I gave up on the idea.
I have not retried recently though.
APB9785
In the docs I noticed this line:
where the “first format” is setting the Plural module in
config.exslike such:Have you tried this as well?
eriklindgren
Thanks for the suggestion @APB9785, yes, I read the same thing and that’s how I configure my custom plural module. It works perfectly when running the app but the mix task still fails.
There’s an easy workaround, you can provide the plural forms as an argument like this
mix gettext.merge priv/gettext/ --locale custom_locale --plural-forms 2as the task only seems to need the plural module to find the number of plural forms, but it would still be nice to understand what I’m doing wrong. I can also go into iex (with -S mix) and call the functions in my module just fine, though I guess that doesn’t prove much of anything.I may well be doing something wrong, but it seems to at least be something missing from the docs about how to get this working in a Phoenix context.
kip
In Gettext.Merger the code to resolve the
n_pluralsfor a locale centres around the following code:Notice that resolving the
n-pluralsduring a merge is:And
read_plural_forms_from_headers/1received headers from the “old”.pofile. In the case of a new locale, the “old” file is actually the.potfile. This from the mix task .Therefore I wonder if the
.potfile has aPlural-Forms:header that is superceding the custom plurals module?Last Post!
c4710n
quoted from docs of gettext:
Because of that, use the global configuration:
Instead of the configuration for a specific backend module:
Then, the problem should be solved.