Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword arguments have to be explicitly double-splatted in Ruby 2.7+ #486

Merged
merged 1 commit into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def translate(key = nil, *, throw: false, raise: false, locale: nil, **options)
# Wrapper for <tt>translate</tt> that adds <tt>:raise => true</tt>. With
# this option, if no translation is found, it will raise <tt>I18n::MissingTranslationData</tt>
def translate!(key, options = EMPTY_HASH)
translate(key, options.merge(:raise => true))
translate(key, **options.merge(:raise => true))
end
alias :t! :translate!

Expand Down
4 changes: 2 additions & 2 deletions lib/i18n/backend/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def localize(locale, object, format = :default, options = EMPTY_HASH)
key = format
type = object.respond_to?(:sec) ? 'time' : 'date'
options = options.merge(:raise => true, :object => object, :locale => locale)
format = I18n.t(:"#{type}.formats.#{key}", options)
format = I18n.t(:"#{type}.formats.#{key}", **options)
end

format = translate_localization_format(locale, object, format, options)
Expand Down Expand Up @@ -143,7 +143,7 @@ def resolve(locale, object, subject, options = EMPTY_HASH)
result = catch(:exception) do
case subject
when Symbol
I18n.translate(subject, options.merge(:locale => locale, :throw => true))
I18n.translate(subject, **options.merge(:locale => locale, :throw => true))
when Proc
date_or_time = options.delete(:object) || object
resolve(locale, object, subject.call(date_or_time, options))
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/gettext/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def N_(msgsid)
end

def gettext(msgid, options = EMPTY_HASH)
I18n.t(msgid, { :default => msgid, :separator => '|' }.merge(options))
I18n.t(msgid, **{:default => msgid, :separator => '|'}.merge(options))
end
alias _ gettext

Expand Down
4 changes: 2 additions & 2 deletions lib/i18n/tests/localization/date.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def setup

test "localize Date: does not modify the options hash" do
options = { :format => '%b', :locale => :de }
assert_equal 'Mär', I18n.l(@date, options)
assert_equal 'Mär', I18n.l(@date, **options)
assert_equal({ :format => '%b', :locale => :de }, options)
assert_nothing_raised { I18n.l(@date, options.freeze) }
assert_nothing_raised { I18n.l(@date, **options.freeze) }
end

test "localize Date: given nil with default value it returns default" do
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tests/localization/procs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module Procs
setup_time_proc_translations
time = ::Time.utc(2008, 3, 1, 6, 0)
options = { :foo => 'foo' }
assert_equal I18n::Tests::Localization::Procs.inspect_args([time, options]), I18n.l(time, options.merge(:format => :proc, :locale => :ru))
assert_equal I18n::Tests::Localization::Procs.inspect_args([time, options]), I18n.l(time, **options.merge(:format => :proc, :locale => :ru))
end

protected
Expand Down
4 changes: 2 additions & 2 deletions lib/i18n/tests/lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ def setup

test "lookup: does not modify the options hash" do
options = {}
assert_equal "a", I18n.t(:string, options)
assert_equal "a", I18n.t(:string, **options)
assert_equal({}, options)
assert_nothing_raised { I18n.t(:string, options.freeze) }
assert_nothing_raised { I18n.t(:string, **options.freeze) }
end

test "lookup: given an array of keys it translates all of them" do
Expand Down
4 changes: 2 additions & 2 deletions test/api/override_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

class I18nOverrideTest < I18n::TestCase
module OverrideInverse
def translate(*args)
super(*args).reverse
def translate(*args, **options)
super(*args, **options).reverse
end
alias :t :translate
end
Expand Down
2 changes: 1 addition & 1 deletion test/backend/cascade_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def setup
end

def lookup(key, options = {})
I18n.t(key, options.merge(:cascade => @cascade_options))
I18n.t(key, **options.merge(:cascade => @cascade_options))
end

test "still returns an existing translation as usual" do
Expand Down
2 changes: 1 addition & 1 deletion test/i18n/exceptions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def force_invalid_locale

def force_missing_translation_data(options = {})
store_translations('de', :bar => nil)
I18n.translate(:foo, options.merge(:scope => :bar, :locale => :de))
I18n.translate(:foo, **options.merge(:scope => :bar, :locale => :de))
rescue I18n::ArgumentError => e
block_given? ? yield(e) : raise(e)
end
Expand Down