CoverallsBuild StatusLast Updated

Phoenix Localized Routes

Localize your Phoenix website with multilingual URL's and custom template assigns; enhancing user engagement and content relevance.

                    =>  /products/:id/edit          @loc.contact = "int@company.com"
/products/:id/edit  =>  /nl/producten/:id/bewerken  @loc.contact = "netherlands@company.com"
                    =>  /es/producto/:id/editar     @loc.contact = "spain@company.com"

Features and Benefits

Status

This lib will soon be published on Hex. In the meantime the documentation can be found at Github Pages

Usage Summary

All links in your application will now automatically use the routes for the set locale.

The full guide is written in the Usage Guide.

Requirements

Example

An example Phoenix application showing the (nested) routes and custom assigns.

git clone https://github.com/BartOtten/phoenix_localized_routes_example.git
cd phoenix_localized_routes_example
iex -S mix phx.server

http://localhost:4000/
http://localhost:4000/europe

http://localhost:4000/products
http://localhost:4000/europe/nl/producten/

Installation

You can install this library by adding it to your list of dependencies in mix.exs:

def deps do
  [
    {:phoenix_localized_routes, "~> 0.1.0"}
  ]
end

To configure your routes have a look at the Usage Guide.

Technical Notes

Phoenix Localized Routes makes use of Macro's to wrap Phoenix Router and Phoenix Router Helpers. It generates alternate helpers and paths based on the routes defined in [YourApp].Routes. Alternate routes are generated at compile time; making them just as fast as the explicitly defined routes.

If a wrapped function call fails, the original function will be called to ensure your application always links to an available page.

To set the custom assigns for use in templates, a Conn.Plug and a helper module with on_mount callback are included.