Skip to content

Keep the text before a binding that follows a literal %{} - #444

Merged
whatyouhide merged 1 commit into
elixir-gettext:mainfrom
oliver-kriska:fix-literal-braces-before-binding
Oct 15, 2026
Merged

whatyouhide merged 1 commit into
elixir-gettext:mainfrom
oliver-kriska:fix-literal-braces-before-binding

Conversation

@oliver-kriska

Copy link
Copy Markdown
Contributor

While splitting a message into interpolation segments, Gettext.Interpolation.Default.to_interpolatable/1 appends a literal %{} to the current segment and keeps scanning. If a binding follows, that segment was dropped instead of being flushed before the binding:

Gettext.Interpolation.Default.to_interpolatable("a %{} b %{c}")
#=> [" b ", :c]          # expected ["a %{} b ", :c]

Gettext.Interpolation.Default.runtime_interpolate("a %{} b %{c}", %{c: "X"})
#=> {:ok, " b X"}        # expected {:ok, "a %{} b X"}

The same function builds the compiled interpolation, so translations containing a literal %{} before a binding lost text at compile time as well. The fix flushes the current segment together with the text before the binding; a literal %{} at the end of a string or in a string without bindings was already handled.

Found while checking output equivalence of an unrelated interpolation change against the previous implementation; tests added for both the segments and the interpolated result.

While splitting a string into interpolation segments, a literal "%{}" is
appended to the current segment and the scan continues. If a binding then
followed, that segment was dropped instead of being flushed before the
binding, so "a %{} b %{c}" interpolated to " b X" at runtime and at compile
time alike.
@whatyouhide

Copy link
Copy Markdown
Contributor

Great find @oliver-kriska 🫶

@whatyouhide
whatyouhide merged commit 45e14f0 into elixir-gettext:main Oct 15, 2026
2 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