Terbium-135
Ex_money: How to translate/localize error messages
For example a Money.UnknownCurrencyError like this:
Usually I am using:
def translate_error(msg) do
Gettext.dgettext(BackendWeb.Gettext, "errors", msg)
end
or Gettext.dngettext
I have the feeling that I am missing the obvious
Looking at:
especially this example
Gettext.dgettext(MyApp.Gettext, "errors", "%{name} is not a valid name", name: "Meg")
#=> "Meg non è un nome valido"
Most Liked
kip
In addition to @LostKobrakai’s insight, the messages from ex_money are most likely not directly translatable since the test message already embeds the invalid content. This was a poor design choice by me for error handling (true across all the ex_cldr-related libs) based upon my misunderstanding of exception handling back many years when I started all this.
I think you may need to pattern match on the exception module in the {:error, {module, message}} tuple and provide your own translatable messages using @LostKobrakai’s suggestion.
I will work out a way to make this more straight forward for the next release of ex_money but I’ve not thought of a good non-breaking strategy yet. Suggestions welcome.
LostKobrakai
You can create .pot files manually. E.g. all the ecto errors are available for translation because phoenix generates a .pot file for it. Nothing in ecto itself knows about gettext.
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
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










