Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kipcole9 committed May 3, 2023
1 parent 4e65d5b commit 8b091aa
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

## Cldr Routes v1.0.0

This is the changelog for Cldr Routes version 1.0.0 released on May 2nd, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_routes/tags)
This is the changelog for Cldr Routes version 1.0.0 released on May 3rd, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_routes/tags)

### Enhancements

* Supports localized verified routes with `~q` (`Sigil_q`).

* Supports Phoenix 1.7 and later only.

* Supports Elixir 1.11 and later only.

## Cldr Routes v0.6.4

This is the changelog for Cldr Routes version 0.6.4 released on April 29th, 2023. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_routes/tags)
Expand Down
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ As a result, users can enter URLs using localised terms which can enhance user e

Similarly, localised path and URL helpers are generated that wrap the standard [Phoenix helpers](https://hexdocs.pm/phoenix/routing.html#path-helpers) to support generating localised paths and URLs.

Lastly, Localized Verified Routes, introduced in Phoenix 1.7, are supported and their use encouraged in preference to URL Helpers. Localized Verified Routes are specified with the `~q` sigil in the same manner as Phoenix Verified Routes `~p`.

## Setting up

A `Cldr` backend module that configures an associated `gettext` backend is required. In addition, a `Gettext` backend must be configured and added to the `Cldr` configuration.
Expand Down Expand Up @@ -165,6 +167,50 @@ def controller do
end
```

## Localized Verified Routes

Sigil_q implements localized verified routes for Phoenix 1.7 and later.

Adding
```
use MyApp.Router.VerifiedRoutes,
router: MyApp.Router,
endpoint: MyApp.Endpoint
```
to a module gives access to `sigil_q` which is functionally equal to Phoenix Verified Routes `sigil_p`. In fact the result of using `sigil_q` is code that looks like this:

```
# ~q"/users" generates the following code for a
# Cldr backend that has configured the locales
# :en, :fr and :de
case MyApp.Cldr.get_locale().cldr_locale_name do
:de -> ~p"/users_de"
:en -> ~p"/users"
:fr -> ~p"/users_fr"
end
```

### Locale interpolation

Some use cases call for the locale, language or territory to be part of the URL. `Sigl_q` makes this easy by providing
the following interpolations into a `Sigil_q` path:

* `:locale` is replaced with Cldr locale name.
* `:language` is replaced with the Cldr language code.
* `:territory` is replaced with the Cldr territory code.

# ~q"/users/:locale" generates the following code for a
# Cldr backend that has configured the locales
# :en, :fr and :de. Note the interpolation of the locale
# information which is performed at compile time.

case MyApp.Cldr.get_locale().cldr_locale_name do
:de -> ~p"/users_de/de"
:en -> ~p"/users/en"
:fr -> ~p"/users_fr/fr"
end
```
## Generating link headers
When the same content is produced in multiple languages it is important to cross-link the different editions of the content to each other. This is good practise in general but strong advised by [goggle](https://developers.google.com/search/docs/advanced/crawling/localized-versions) to reduce SEO risks for your site.
Expand Down Expand Up @@ -249,7 +295,7 @@ The package can be installed by adding `ex_cldr_routes` to your list of dependen
```elixir
def deps do
[
{:ex_cldr_routes, "~> 0.6.0"}
{:ex_cldr_routes, "~> 1.0.0"}
]
end
```
Expand Down
20 changes: 16 additions & 4 deletions lib/cldr/route.ex
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,9 @@ defmodule Cldr.Route do
router: MyApp.Router,
endpoint: MyApp.Endpoint
```
to a module gives access to `sigil_q` which is used identically to
Phoenix `sigil_p`. In fact the result of using `sigil_q` is code that
looks like this:
to a module gives access to `sigil_q` which is functionally equal to
Phoenix Verified Routes `sigil_p`. In fact the result of using `sigil_q`
is code that looks like this:
```
# ~q"/users" generates the following code for a
Expand All @@ -368,6 +368,16 @@ defmodule Cldr.Route do
end
```
### Locale interpolation
Some use cases call for the locale, language or territory
to be part of the URL. `Sigl_q` makes this easy by providing
the following interpolations:
`:locale` is replaced with cldr locale name.
`:language` is replaced with the cldr language code.
`:territory` is replaced with the cldr territory code.
"""
defmacro sigil_q({:<<>>, _meta, _segments} = route, flags) do
import Cldr.Route
Expand Down Expand Up @@ -699,7 +709,9 @@ defmodule Cldr.Route do
end

defp translate_segment_part(":locale", _gettext_backend, locale) do
locale.canonical_locale_name
locale.cldr_locale_name
|> to_string()
|> String.downcase()
end

defp translate_segment_part(":territory", _gettext_backend, locale) do
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule CldrRoutes.MixProject do
[
app: :ex_cldr_routes,
version: @version,
elixir: "~> 1.10",
elixir: "~> 1.11",
description: "Cldr-based localized route generation and path helpers for Phoenix",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
Expand Down Expand Up @@ -58,7 +58,7 @@ defmodule CldrRoutes.MixProject do
{:jason, "~> 1.0"},
{:gettext, "~> 0.19"},
{:ex_doc, "~> 0.18", only: [:release, :dev]},
{:dialyxir, "~> 1.0", only: [:dev], runtime: false, optional: true}
{:dialyxir, "~> 1.0", only: [:dev, :release], runtime: false, optional: true}
]
end

Expand Down

0 comments on commit 8b091aa

Please sign in to comment.