Skip to content

Commit

Permalink
Merge pull request #491 from ruby-i18n/pipe-interpolation
Browse files Browse the repository at this point in the history
Allow pipes in interpolations
  • Loading branch information
radar authored Oct 4, 2019
2 parents 2942126 + 0c647ce commit 9afdd61
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/i18n/interpolate/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module I18n
DEFAULT_INTERPOLATION_PATTERNS = [
/%%/,
/%\{(\w+)\}/, # matches placeholders like "%{foo}"
/%\{([\w|]+)\}/, # matches placeholders like "%{foo} or %{foo|word}"
/%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
].freeze
INTERPOLATION_PATTERN = Regexp.union(DEFAULT_INTERPOLATION_PATTERNS)
Expand Down
4 changes: 4 additions & 0 deletions lib/i18n/tests/interpolation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ module Interpolation
assert_equal 'Hi David!', interpolate(:default => 'Hi %{name}!', :name => 'David')
end

test "interpolation: works with a pipe" do
assert_equal 'Hi david!', interpolate(:default => 'Hi %{name|lowercase}!', :'name|lowercase' => 'david')
end

test "interpolation: given a nil value it still interpolates it into the string" do
assert_equal 'Hi !', interpolate(:default => 'Hi %{name}!', :name => nil)
end
Expand Down

0 comments on commit 9afdd61

Please sign in to comment.