View Source Routex.Extension.Translations (Phoenix Routes Extension Framework v0.3.0-alpha.4)

Enables users to enter URLs using localized terms which can enhance user engagement and content relevance.

Extracts segments of a routes' path to a translations domain file (default: routes.po) for translation. At compile-time it combines the translated segments to transform routes.

This extension expects either a :language attribute or a :locale attribute. When only :locale is provided it will try to extract the language from the locale tag. This algorithm is covers Alpha-2 and Alpha-3 codes (see: ISO)

Configuration

defmodule ExampleWeb.RoutexBackend do
use Routex.Backend,
extensions: [
+ Routex.Extension.Translations,
  Routex.Extension.AttrGetters
]
+ translations_backend: MyApp.Gettext,
+ translations_domain: "routes",

Pseudo result

# when translated to Spanish in the .po file
# - products: producto
# - edit: editar

/products/:id/edit   /producto/:id/editar

Routex.Attrs

Requires

  • language || locale

Sets

  • none

Use case(s)

This extension can be combined with Routex.Extension.Alternatives to create multilingual routes.

Use Alternatives to create new branches and provide a :language or :locale per branch and Translations to translate the alternative routes.

                     /products/:id/edit                  language: "en"
/products/:id/edit   /nederland/producten/:id/bewerken   language: "nl"
                     /espana/producto/:id/editar         language: "es"