View Source PhxLocalizedRoutes.Router (Phoenix Localized Routes v0.1.2)
Provides macro localize
to generate localized and
multilingual Phoenix routes with configurable assigns
which can be used in Controllers and (Live)Views.
usage
Usage
Instructions how to use this module can be found in the Usage Guide.
Link to this section Summary
Functions
Macro which creates an alternative Router Helpers module
named [MyApp].Router.Helpers.Localized
based on the original helper
module generated by Phoenix ([MyApp].Router.Helpers
).
Generate localized routes and route helper modules.
Link to this section Functions
Macro which creates an alternative Router Helpers module
named [MyApp].Router.Helpers.Localized
based on the original helper
module generated by Phoenix ([MyApp].Router.Helpers
).
- the new helper module is aliased as
Routes
; making it a drop-in replacement. - the original Router Helper module is aliased as
OriginalRoutes
. - localised path and URL helpers are generated to support generating localised path and URLs. The localized helpers wrap the standard Phoenix helpers.
Pseudo code
def product_index_path(arg1, arg2) do
PhxLocalizedRoutes.Helper.loc_route(OriginalRoutes.product_index_path(arg1, arg2), loc_opts)
end
def product_index_path(arg1, arg2, arg3) do
PhxLocalizedRoutes.Helper.loc_route(OriginalRoutes.product_index_path(arg1, arg2, arg3), loc_opts)
end
[...]
@spec localize(module(), opts :: list(), [{:do, Macro.t()}]) :: Macro.output()
Generate localized routes and route helper modules.
This module when use
d , provides a localize/1
macro that is designed to wrap the standard Phoenix
route macros such as get/3
, put/3
and live/3
in alternate scopes as defined in the config module.
When a Gettext
module is defined in the configuration,
it is used to make route (URL) parts translatable / multilingual.
Translations for the parts of a given route path are translated at compile-time which are then combined into a localised route that is added to the standard Phoenix routing framework.
As a result, users can enter URLs using localised terms which can enhance user engagement and content relevance.
=> pl: produkty | edytować
/products/:id/edit => nl: producten | bewerken
=> es: producto | editar
Similarly, localised path and URL helpers are generated that wrap the standard Phoenix helpers to supporting generating localised path and URLs.