Skip to content

Commit

Permalink
Simplify LocaleFallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
henrik committed Aug 13, 2014
1 parent 3cff249 commit be386c0
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/traco/locale_fallbacks.rb
Expand Up @@ -17,23 +17,17 @@ def initialize(fallback_option)
@available_locales = I18n.available_locales.sort
end

def [](for_locale)
chain = [for_locale]
chain << @default_locale if include_default_locale?
chain |= @available_locales if include_available_locales?
chain
def [](current_locale)
case fallback_option
when DEFAULT_FALLBACK then [ current_locale, @default_locale ]
when ANY_FALLBACK then [ current_locale, @default_locale, *@available_locales ].uniq
when NO_FALLBACK then [ current_locale ]
else raise "Unknown fallback." # Should never get here.
end
end

private

def include_default_locale?
[ DEFAULT_FALLBACK, ANY_FALLBACK ].include?(fallback_option)
end

def include_available_locales?
ANY_FALLBACK == fallback_option
end

def validate_option(fallback_option)
if OPTIONS.include?(fallback_option)
fallback_option
Expand Down

0 comments on commit be386c0

Please sign in to comment.