Translate only the literal path of a ~q route - #17
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two bugs in how
~qtranslates a route, with one change.Before
Problem
/inside the query hides the real end of the path. The path stays untranslated, and a query value is translated instead. Literal text after an interpolated query value (?page=#{page}&next=/users) is also translated.#{...}code are translated too. A literal that matches aroutesmsgid (a default value, a map key, a branch result) is silently replaced at compile time.After
Details
Localize.Routes.translate_path_now/4usedMacro.prewalk/2, which also visits the code inside each interpolation.translate_segment_parts/4split each literal on/first and only looked for?or#in the last piece.translate_path_now/4walks only the top-level<<>>segments withEnum.map_reduce/3. Each literal is split once at the first?or#; only the part before it is translated, and every later segment is left as is. Interpolation segments are never walked.~q,path_for/2andurl_for/2always pass a<<>>node (normalize_route_ast/1). The now unused catch-all clause ofmerge_literal_segments/1is removed (the compiler flagged it).test/sigil_q_test.exs, both fail onmain:sigil_q translates the path but not a path in the queryandsigil_q does not translate string literals in interpolated code.mix test(269 passed),mix compile --warnings-as-errors,mix format --check-formatted,mix credo --strict(only the existingSigil_q.InterpolationTestname note).AI disclosure: AI models helped us find this issue, write the change, and review it.