Skip to content

Commit 9afdd61

Browse files
authored
Merge pull request #491 from ruby-i18n/pipe-interpolation
Allow pipes in interpolations
2 parents 2942126 + 0c647ce commit 9afdd61

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/i18n/interpolate/ruby.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module I18n
55
DEFAULT_INTERPOLATION_PATTERNS = [
66
/%%/,
7-
/%\{(\w+)\}/, # matches placeholders like "%{foo}"
7+
/%\{([\w|]+)\}/, # matches placeholders like "%{foo} or %{foo|word}"
88
/%<(\w+)>(.*?\d*\.?\d*[bBdiouxXeEfgGcps])/ # matches placeholders like "%<foo>.d"
99
].freeze
1010
INTERPOLATION_PATTERN = Regexp.union(DEFAULT_INTERPOLATION_PATTERNS)

lib/i18n/tests/interpolation.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ module Interpolation
2424
assert_equal 'Hi David!', interpolate(:default => 'Hi %{name}!', :name => 'David')
2525
end
2626

27+
test "interpolation: works with a pipe" do
28+
assert_equal 'Hi david!', interpolate(:default => 'Hi %{name|lowercase}!', :'name|lowercase' => 'david')
29+
end
30+
2731
test "interpolation: given a nil value it still interpolates it into the string" do
2832
assert_equal 'Hi !', interpolate(:default => 'Hi %{name}!', :name => nil)
2933
end

0 commit comments

Comments
 (0)