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

Should not allow noop arguments for I18n.t #545

Merged
merged 1 commit into from
Jan 1, 2021
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
8 changes: 4 additions & 4 deletions lib/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def eager_load!
# I18n.t(:salutation, { :gender => 'w', :name => 'Smith' })
# I18n.t(:salutation, any_hash)
#
def translate(key = nil, *, throw: false, raise: false, locale: nil, **options) # TODO deprecate :raise
def translate(key = nil, throw: false, raise: false, locale: nil, **options) # TODO deprecate :raise
locale ||= config.locale
raise Disabled.new('t') if locale == false
enforce_available_locales!(locale)
Expand All @@ -217,8 +217,8 @@ 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))
def translate!(key, **options)
translate(key, **options, raise: true)
end
alias :t! :translate!

Expand Down Expand Up @@ -281,7 +281,7 @@ def exists?(key, _locale = nil, locale: _locale, **options)
# I18n.transliterate("Jürgen") # => "Juergen"
# I18n.transliterate("Jürgen", :locale => :en) # => "Jurgen"
# I18n.transliterate("Jürgen", :locale => :de) # => "Juergen"
def transliterate(key, *, throw: false, raise: false, locale: nil, replacement: nil, **options)
def transliterate(key, throw: false, raise: false, locale: nil, replacement: nil, **options)
locale ||= config.locale
raise Disabled.new('transliterate') if locale == false
enforce_available_locales!(locale)
Expand Down
6 changes: 3 additions & 3 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, **options)
super(*args, **options).reverse
def translate(key, **options)
super(key, **options).reverse
end
alias :t :translate
end
Expand Down Expand Up @@ -33,7 +33,7 @@ def setup

test "make sure modules can overwrite I18n signature" do
exception = catch(:exception) do
@I18n.t('Hello', 'Welcome message on home page', :tokenize => true, :throw => true)
@I18n.t('Hello', :tokenize => true, :throw => true)
end
assert exception.message
@I18n.extend OverrideSignature
Expand Down