Localize.VerifiedRoutes (Localize Web v0.2.0)

Copy Markdown View Source

Localized verified routes using the ~q sigil.

This module provides compile-time verified localized routes. Instead of configuring with use Phoenix.VerifiedRoutes, configure instead:

use Localize.VerifiedRoutes,
  router: MyApp.Router,
  endpoint: MyApp.Endpoint,
  gettext: MyApp.Gettext

When configured, the sigil ~q is made available to express localized verified routes. Sigil ~p remains available for non-localized verified routes.

The ~q sigil generates a case statement that dispatches to the appropriate localized ~p route based on the current locale:

# ~q"/users" generates:
case Localize.get_locale().cldr_locale_id do
  :de -> ~p"/benutzer"
  :en -> ~p"/users"
  :fr -> ~p"/utilisateurs"
end

Locale Interpolation

  • :locale is replaced with the CLDR locale name.

  • :language is replaced with the CLDR language code.

  • :territory is replaced with the CLDR territory code.

Summary

Functions

Implements the ~q sigil for localized verified routes.

Generates the router url with localized route verification.

Generates the router url with localized route verification from the connection, socket, or URI.

Generates the router url with localized route verification from the connection, socket, or URI and router.

Functions

sigil_q(route, flags)

(macro)

Implements the ~q sigil for localized verified routes.

Generates a case expression that dispatches to the translated ~p route for the current locale. The route path is verified at compile time against the router.

url(route)

(macro)

Generates the router url with localized route verification.

url(conn_or_socket_or_endpoint_or_uri, route)

(macro)

Generates the router url with localized route verification from the connection, socket, or URI.

url(conn_or_socket_or_endpoint_or_uri, router, route)

(macro)

Generates the router url with localized route verification from the connection, socket, or URI and router.