Closed rubas closed 2 years ago
@rubas Thank you for the report and my apologies for the inconvenience. I'll take a look at this on Sunday (I'm in transit all of tomorrow). Hope thats ok. Will revert ASAP. The Helpers are borrowed from Phoenix and despite some tests, clearly not good enough. I'll get this sorted out.
Apologies for not meeting my own deadline, the day job is definitely impacting this week. I will get to this as quickly as I can.
This is the worst time-to-resolution in my 6 years of building ex_cldr
, my sincere apologies.
As of commit f98f6c5 I have rewritten the LocalizedHelpers
module and I'm much happier with the implementation since it no longer forks the Phoenix Helpers
module.
There is one open issue I need to fix which is that if you specify an :as
option to a route it will be overwritten. This is because I am using the :as
option to generate one route helper per locale and using the :as
option to differentiate.
I will be able to honour the :as
option (still appending a locale name) and thats the last step before release I believe.
Nevertheless I wanted to share this with you as quickly as possible to get your feedback. The changelog entry currently reads:
Add support for live
routes. Thanks to @ringofhealth for the report. Closes #1.
Uses the macros from Gettext rather than the functions when generating routes. This means that the mix tasks gettext.extract
and gettext.merge
now work as expected.
Rewrite the LocalizedHelpers
module that now proxies into the standard Phoenix Helpers
module rather than maintaining a separate forked module. As a result:
Helpers
module now generates helper names that have locale suffixes. That is user_path
becomes user_en_path
, user_fr_path
and so on.LocalizedHelpers
module hosts the standard helper names (like user_path
) which will then call the appropriate standard helper depending on the result of Cldr.get_locale/1
.Thanks to @rubas and @ringofhealth for their extreme patience while I worked this through. Closes #1, and #4.
Additional testing found a bug in helper generation so I recommend holding off reviewing for now. Will have this resolved today.
OK, I think its ready for a workout now. As of commit 415b9fb any :as
parameter is honoured. In addition, error messages are aligned to the standard Phoenix routing error messages/exceptions.
At the moment any errors associated with calling a valid helper, but a helper that is not localised for the current locale, will raise a Phoenix standard error but not mention an issue related to locales. Thats the next step and, I hope, the last one before the next release.
I will tackle the issue of route prefixes after that.
BTW, I neglected to note that the locale that is used to drive localised routes is the Cldr
locale (ie, derived from calling Cldr.get_locale/1
. Its the associated :gettext_locale_name
that is used to drive translations. But the correct approach is either:
iex> MyApp.Cldr.put_locale "de"
{:ok, #Cldr.LanguageTag<de [validated]>}
iex> MyApp.Router.LocalizedHelpers.user_path %Plug.Conn{}, :index
"/users_de"
Or
iex> Cldr.with_locale("de", MyApp.Cldr, fn ->
MyApp.Router.LocalizedHelpers.user_path %Plug.Conn{}, :index
end)
"/users_de"
Version: 0.3-dev
Somehow we can't get the
LocalizedHelper
to work. It's not respecting the current locale and takes always the first defined route.ex_cldr_routes
(including the LocalizedHelpers) are passing, but we can't find any meaningful difference between your test and our setup.What are we missing? 😵💫
Routes
Config
Router
Cldr
Gettext
config.exs