Skip to content

Commit

Permalink
Nodoc and document new internal method [ci skip]
Browse files Browse the repository at this point in the history
Also improve docs on enforce available locale related methods.
  • Loading branch information
carlosantoniodasilva committed May 7, 2014
1 parent bc3ca88 commit 3f30eb4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 3 additions & 6 deletions lib/i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,13 @@ def normalize_keys(locale, key, scope, separator = nil)
keys
end

# Returns true when the passed locale is in I18.available_locales.
# Returns false otherwise.
# Compare with Strings as `locale` may be coming from user input
# Returns true when the passed locale, which can be either a String or a
# Symbol, is in the list of available locales. Returns false otherwise.
def locale_available?(locale)
I18n.config.available_locales_set.include?(locale)
end

# Raises an InvalidLocale exception when the passed locale is not
# included in I18n.available_locales.
# Returns false otherwise
# Raises an InvalidLocale exception when the passed locale is not available.
def enforce_available_locales!(locale)
handle_enforce_available_locales_deprecation

Expand Down
4 changes: 3 additions & 1 deletion lib/i18n/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def available_locales
@@available_locales || backend.available_locales
end

def available_locales_set
# Caches the available locales list as both strings and symbols in a Set, so
# that we can have faster lookups to do the available locales enforce check.
def available_locales_set #:nodoc:
@@available_locales_set ||= available_locales.inject(Set.new) do |set, locale|
set << locale.to_s << locale.to_sym
end
Expand Down

0 comments on commit 3f30eb4

Please sign in to comment.