You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,12 @@
2
2
3
3
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
4
5
+
## [0.6.0] - 2026-05-11
6
+
7
+
### Enhancements
8
+
9
+
* Add `path_for/2` and `url_for/2` macros to `Localize.VerifiedRoutes` to render a verified path or URL in an explicit locale without changing the process-wide locale, supporting language-switcher and hreflang use cases that need every configured locale rendered in one template pass.
Copy file name to clipboardExpand all lines: guides/phoenix-localized-routing.md
+35Lines changed: 35 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -257,6 +257,41 @@ The `~q` sigil supports the same locale interpolations as the `localize` macro:
257
257
# Produces "/fr/pages_fr/intro" when the locale is :fr
258
258
```
259
259
260
+
### Rendering a Path or URL in a Specific Locale
261
+
262
+
`~q` dispatches on the *current* process locale (`Localize.get_locale/0`). When you need to render a link in a different locale at the call site — without changing the process locale — use `path_for/2` and `url_for/2`. Typical use cases are language switchers and emitting hreflang links per locale in one template pass.
`url_for/2` returns a full URL via `Phoenix.VerifiedRoutes.url/1`:
278
+
279
+
```elixir
280
+
url_for(:fr, "/users")
281
+
#=> "http://localhost:4000/users_fr"
282
+
```
283
+
284
+
The route argument accepts the same form as `~q` — a string literal with optional `#{...}` interpolations and `:locale` / `:language` / `:territory` substitutions.
285
+
286
+
For ad-hoc blocks where you need a whole region of code to run under a specific locale (perhaps because you also want locale-sensitive number or date formatting), `Localize.with_locale/2` temporarily switches the locale and restores it afterwards:
287
+
288
+
```elixir
289
+
Localize.with_locale(:fr, fn->~q"/users"end)
290
+
#=> "/users_fr"
291
+
```
292
+
293
+
Use `path_for/2` for single-call locale forcing; use `Localize.with_locale/2` for whole-block temporary locale changes.
294
+
260
295
## Inspecting Localized Routes
261
296
262
297
Localized routes are stored in a `LocalizedRoutes` submodule. You can inspect them with the `phx.routes` mix task:
0 commit comments