Skip to content

Commit ef62253

Browse files
authored
Merge pull request #726 from byroot/fstr-compat
Fix compatibility with `--enable-frozen-string-literal`
2 parents dee96b6 + 0022013 commit ef62253

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

.github/workflows/ruby.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
strategy:
1818
fail-fast: false
1919
matrix:
20+
rubyopt: [""]
2021
ruby_version: [head, 3.4, 3.3, 3.2, jruby]
2122
gemfile:
2223
- Gemfile
@@ -34,6 +35,10 @@ jobs:
3435
gemfile: gemfiles/Gemfile.rails-8.0.x
3536
- ruby_version: jruby
3637
gemfile: gemfiles/Gemfile.rails-main
38+
include:
39+
- ruby_version: 3.4
40+
gemfile: Gemfile
41+
rubyopt: "--enable-frozen-string-literal --debug-frozen-string-literal"
3742

3843
runs-on: ubuntu-latest
3944

lib/i18n/backend/interpolation_compiler.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Compiler
2525

2626
def compile_if_an_interpolation(string)
2727
if interpolated_str?(string)
28+
string = +string
2829
string.instance_eval <<-RUBY_EVAL, __FILE__, __LINE__
2930
def i18n_interpolate(v = {})
3031
"#{compiled_interpolation_body(string)}"

lib/i18n/tests/interpolation.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ module Interpolation
8989
end
9090

9191
test "interpolation: ASCII strings in the backend should be encoded to UTF8 if interpolation options are in UTF8" do
92-
I18n.backend.store_translations 'en', 'encoding' => ('%{who} let me go'.force_encoding("ASCII"))
92+
I18n.backend.store_translations 'en', 'encoding' => ('%{who} let me go'.dup.force_encoding(Encoding::US_ASCII))
9393
result = I18n.t 'encoding', :who => "måmmå miå"
9494
assert_equal Encoding::UTF_8, result.encoding
9595
end
9696

9797
test "interpolation: UTF8 strings in the backend are still returned as UTF8 with ASCII interpolation" do
9898
I18n.backend.store_translations 'en', 'encoding' => 'måmmå miå %{what}'
99-
result = I18n.t 'encoding', :what => 'let me go'.force_encoding("ASCII")
99+
result = I18n.t 'encoding', :what => 'let me go'.dup.force_encoding(Encoding::US_ASCII)
100100
assert_equal Encoding::UTF_8, result.encoding
101101
end
102102

@@ -172,7 +172,7 @@ def capture(stream)
172172
end
173173

174174
def euc_jp(string)
175-
string.encode!(Encoding::EUC_JP)
175+
string.encode(Encoding::EUC_JP)
176176
end
177177

178178
def interpolate(*args)

test/backend/metadata_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def setup
3838
end
3939

4040
test "pluralization adds the count to metadata on Strings" do
41-
assert_equal(1, I18n.t(:missing, :count => 1, :default => { :one => 'foo' }).translation_metadata[:count])
41+
assert_equal(1, I18n.t(:missing, :count => 1, :default => { :one => +'foo' }).translation_metadata[:count])
4242
end
4343

4444
test "metadata works with frozen values" do

0 commit comments

Comments
 (0)