Cldr.Routes.LocalizedHelpers (Cldr Routes v1.4.0)
View SourceGenerates a module that implements localised helpers.
It introspects the generated helpers module and creates a wrapper function that translates (at compile time) the path segments.
Summary
Functions
For a given set of routes, define a LocalizedHelpers module that implements localized helpers.
Generates HTML link tags for a given map of locale => URLs
Types
Functions
For a given set of routes, define a LocalizedHelpers module that implements localized helpers.
@spec hreflang_links(%{required(locale_name()) => url()}) :: Phoenix.HTML.safe()
Generates HTML link tags for a given map of locale => URLs
This function generates <link ... /> tags that should be placed in the
<head> section of an HTML document to indicate the different language
versions of a given page.
The MyApp.Router.LocalizedHelpers.<helper>_link functions can
generate the required mapping from locale to URL for a given helper.
These _link helpers take the same arguments as the _path and
_url helpers.
If the helper refers to a route that is not localized then an empty string will be returned since there are no alternative localizations of this route.
See https://developers.google.com/search/docs/advanced/crawling/localized-versions#http
Examples
iex> links = %{
...> "en" => "https://localhost/users/1",
...> "fr" => "https://localhost/utilisateurs/1"
...> }
iex> Cldr.Routes.LocalizedHelpers.hreflang_links(links)
{
:safe,
[
[60, "link", [32, "href", 61, 34, "https://localhost/users/1", 34, 32, "hreflang", 61, 34, "en", 34, 32, "rel", 61, 34, "alternate", 34], 62],
10,
[60, "link", [32, "href", 61, 34, "https://localhost/utilisateurs/1", 34, 32, "hreflang", 61, 34, "fr", 34, 32, "rel", 61, 34, "alternate", 34], 62]
]
}
iex> Cldr.Routes.LocalizedHelpers.hreflang_links(nil)
{:safe, []}
iex> Cldr.Routes.LocalizedHelpers.hreflang_links(%{})
{:safe, []}