Skip to content

Commit

Permalink
Fix a naming clash between I18n.enforce_available_locales and I18n.co…
Browse files Browse the repository at this point in the history
…nfig.enforce_available_locales

Renamed `I18n.enforce_available_locales` method to `I18n.enforce_available_locales!`
  • Loading branch information
tigrish committed Dec 3, 2013
1 parent 95ae5a8 commit 16904a7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def translate(*args)
locale = options.delete(:locale) || config.locale
handling = options.delete(:throw) && :throw || options.delete(:raise) && :raise # TODO deprecate :raise

enforce_available_locales(locale)
enforce_available_locales!(locale)
raise I18n::ArgumentError if key.is_a?(String) && key.empty?

result = catch(:exception) do
Expand Down Expand Up @@ -231,7 +231,7 @@ def transliterate(*args)
locale = options && options.delete(:locale) || config.locale
handling = options && (options.delete(:throw) && :throw || options.delete(:raise) && :raise)
replacement = options && options.delete(:replacement)
enforce_available_locales(locale)
enforce_available_locales!(locale)
config.backend.transliterate(locale, key, replacement)
rescue I18n::ArgumentError => exception
handle_exception(handling, exception, locale, key, options || {})
Expand All @@ -242,7 +242,7 @@ def localize(object, options = nil)
options = options ? options.dup : {}
locale = options.delete(:locale) || config.locale
format = options.delete(:format) || :default
enforce_available_locales(locale)
enforce_available_locales!(locale)
config.backend.localize(locale, object, format, options)
end
alias :l :localize
Expand Down Expand Up @@ -281,7 +281,7 @@ def locale_available?(locale)
# Raises an InvalidLocale exception when the passed locale is not
# included in I18n.available_locales.
# Returns false otherwise
def enforce_available_locales(locale)
def enforce_available_locales!(locale)
handle_enforce_available_locales_deprecation

if config.enforce_available_locales
Expand Down
4 changes: 2 additions & 2 deletions lib/i18n/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def locale

# Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
def locale=(locale)
I18n.enforce_available_locales(locale)
I18n.enforce_available_locales!(locale)
@locale = locale.to_sym rescue nil
end

Expand All @@ -29,7 +29,7 @@ def default_locale

# Sets the current default locale. Used to set a custom default locale.
def default_locale=(locale)
I18n.enforce_available_locales(locale)
I18n.enforce_available_locales!(locale)
@@default_locale = locale.to_sym rescue nil
end

Expand Down
4 changes: 2 additions & 2 deletions test/i18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def call(exception, locale, key, options); key; end
test "I18n.enforce_available_locales raises an I18n::InvalidLocale when the passed locale is unavailable" do
begin
I18n.config.enforce_available_locales = true
assert_raise(I18n::InvalidLocale) { I18n.enforce_available_locales(:klingon) }
assert_raise(I18n::InvalidLocale) { I18n.enforce_available_locales!(:klingon) }
ensure
I18n.config.enforce_available_locales = false
end
Expand All @@ -348,7 +348,7 @@ def call(exception, locale, key, options); key; end
I18n.available_locales = [:en, :de]
begin
I18n.config.enforce_available_locales = true
assert_nothing_raised { I18n.enforce_available_locales(:en) }
assert_nothing_raised { I18n.enforce_available_locales!(:en) }
ensure
I18n.config.enforce_available_locales = false
end
Expand Down

0 comments on commit 16904a7

Please sign in to comment.