Skip to content

Commit f89eae3

Browse files
committed
fix ruby 3.0 keyword arguments
1 parent 2a3f5b3 commit f89eae3

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby 3.0.0

lib/phraseapp-in-context-editor-ruby/backend_service.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,27 @@ def initialize(args = {})
1414

1515
def translate(*args)
1616
if to_be_translated_without_phraseapp?(args)
17-
I18n.translate_without_phraseapp(*args)
17+
# *Ruby 2.7+ keyword arguments warning*
18+
#
19+
# This method uses keyword arguments.
20+
# There is a breaking change in ruby that produces warning with ruby 2.7 and won't work as expected with ruby 3.0
21+
# The "hash" parameter must be passed as keyword argument.
22+
#
23+
# Good:
24+
# I18n.t(:salutation, :gender => 'w', :name => 'Smith')
25+
# I18n.t(:salutation, **{ :gender => 'w', :name => 'Smith' })
26+
# I18n.t(:salutation, **any_hash)
27+
#
28+
# Bad:
29+
# I18n.t(:salutation, { :gender => 'w', :name => 'Smith' })
30+
# I18n.t(:salutation, any_hash)
31+
#
32+
kw_args = args[1]
33+
if kw_args.present?
34+
I18n.translate_without_phraseapp(args[0], **kw_args)
35+
else
36+
I18n.translate_without_phraseapp(args[0])
37+
end
1838
else
1939
phraseapp_delegate_for(args)
2040
end

spec/phraseapp-in-context-editor-ruby/backend_service_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@
134134

135135
it { is_expected.to eql "translation missing: en.context.key" }
136136
end
137+
138+
context "scope array given in rails 3 style" do
139+
let(:context_key_translation) { double }
140+
let(:args) { [:key, **{ :scope => [:context] }] }
141+
142+
it { is_expected.to eql "translation missing: en.context.key" }
143+
end
137144
end
138145
end
139146
end

0 commit comments

Comments
 (0)