Skip to content

Translate nested resources under a parent with options - #18

Merged
kipcole9 merged 1 commit into
elixir-localize:mainfrom
rubas:fix/nested-resources-with-options
Sep 27, 2026
Merged

kipcole9 merged 1 commit into
elixir-localize:mainfrom
rubas:fix/nested-resources-with-options

Conversation

@rubas

@rubas rubas commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Before

localize [:fr] do
  resources "/users", UserController, only: [:index] do
    resources "/faces", FaceController, only: [:index]
  end
end

Enum.map(MyRouter.__routes__(), & &1.path)
#=> ["/users_fr", "/users_fr/:user_id/faces"]

Problem

  • The nested-resources rewrite in localize/2 matches a parent only when it has no options.
  • With options on the parent, such as only: or except:, the child path is not translated, while the same block without options works.

After

Enum.map(MyRouter.__routes__(), & &1.path)
#=> ["/users_fr", "/users_fr/:user_id/faces_fr"]
Details
  • Cause: Localize.Routes.localize/2 has a clause for resources path, controller do ... end but none for resources path, controller, options do ... end. That shape fell through to the plain verb clause, which translates only the parent path.
  • Change: a second clause for the four-argument form that keeps the options and rewrites the nested block the same way. Deeper levels already handle options in localize_nested_resources/2.
  • scope is not in the localizable verbs, so there is no matching gap for scope with options.
  • Test: Nested resources a parent with options translates the nested path in test/routes_test.exs, which fails on main.
  • Checks: mix test (268 passed), mix compile --warnings-as-errors, mix format --check-formatted, mix credo --strict (only the existing Sigil_q.InterpolationTest name note).

AI disclosure: AI models helped us find this issue, write the change, and review it.

@kipcole9
kipcole9 merged commit ae4109e into elixir-localize:main Sep 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants