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

Adapter for projects using :ex_cldr. It generates the configuration for Routex.Extension.Alternatives.

Interpolating Locale Data

Interpolation is provided by Routex.Extension.Interpolation, which is able to use any Routex.Attr for interpolation. See it's documentation for additional options.

When using this Cldr extension, the following interpolations are supported as they are set as Routex.Attr:

  • locale will interpolate the Cldr locale name
  • locale_display will interpolate the Cldr locale display name
  • language will interpolate the Cldr language name
  • territory will interpolate the Cldr territory code

Some examples are:

preprocess_using ExampleWeb.RoutexBackend do
  scope "/#{territory}/territory/" do
    get "/#{locale}/locale/pages/:page", PageController, :show
    get "/language/#{language}/pages/:page", PageController, :show
  end
end

Configuration

defmodule ExampleWeb.RoutexBackend do
use Routex.Backend,
extensions: [
+ Routex.Extension.Cldr,
+ Routex.Extension.Alternatives,
+ Routex.Extension.Interpolation, #  when using routes with interpolation
+ Routex.Extension.Translations,  # when using translated routes
+ Routex.Extension.VerifiedRoutes,
  [...]
  Routex.Extension.AttrGetters
],
+ cldr_backend: MyApp.Cldr,
+ translations_backend: MyApp.Gettext,  #  when using translated routes
+ translations_domain: "routes",  #  when using translated routes
+ alternatives_prefix: false,  #  when using routes with interpolation
+ verified_sigil_routex: "~q", #  consider using ~p, see `Routex.Extension.VerifiedRoutes`
defmodule ExampleWeb.Router
# require your Cldr backend module before `use`ing the router.
+ require ExampleWeb.Cldr

use ExampleWeb, :router

import ExampleWeb.UserAuth

When your application does not compile after adding this extension, force a recompile using mix compile --force.

Pseudo result

This extension injects :alternatives into your configuration. See the documentation of Routex.Extension.Alternatives to see more options and the pseudo result.

 alternatives: %{
  "/" => %{
    attrs: %{
      language: "en",
      locale: "en",
      territory: "US",
      locale_display: "English (United States)"
    },
    branches: %{
      "/en" => %{
        language: "en",
        locale: "en",
        territory: "US",
        locale_dispay: "English"
      },
      "/fr" => %{
        language: "fr",
        locale: "fr",
        territory: "FR",
        locale_display: "français"
      }
   }
 }

Routex.Attrs

Requires

  • none

Sets

  • language
  • locale
  • locale_display
  • territory

Summary

Functions

Link to this function

configure(config, backend)

View Source

Callback implementation for Routex.Extension.configure/2.

Link to this function

display_name(locale, backend)

View Source