diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/routing_filters.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/routing_filters.rb b/lib/routing_filters.rb index cdb58e7c1..32dafc651 100644 --- a/lib/routing_filters.rb +++ b/lib/routing_filters.rb @@ -5,5 +5,22 @@ module RoutingFilter def prepend_locale?(locale) locale && I18n.available_locales.length > 1 && (self.class.include_default_locale? || !default_locale?(locale)) end + # And override the generation logic to use FastGettext.locale + # rather than I18n.locale (the latter is what rails uses + # internally and may look like `en_US`, whereas the latter is + # was FastGettext and other POSIX-based systems use, and will + # look like `en_US` + def around_generate(*args, &block) + params = args.extract_options! # this is because we might get a call like forum_topics_path(forum, topic, :locale => :en) + + locale = params.delete(:locale) # extract the passed :locale option + locale = FastGettext.locale if locale.nil? # default to I18n.locale when locale is nil (could also be false) + locale = nil unless valid_locale?(locale) # reset to no locale when locale is not valid + args << params + + yield.tap do |result| + prepend_segment!(result, locale) if prepend_locale?(locale) + end + end end end |