Sha256: 124fb94c4783aff57805bab69c96dcab1ce9c03528740de6a559e6599c114b3a

Contents?: true

Size: 1005 Bytes

Versions: 20

Compression:

Stored size: 1005 Bytes

Contents

module RoutingFilter
  class RefineryLocales < Filter

    def around_recognize(path, env, &block)
      if ::Refinery::I18n.enabled?
        if path =~ %r{^/(#{::Refinery::I18n.locales.keys.join('|')})(/|$)}
          path.sub! %r(^/(([a-zA-Z\-_])*)(?=/|$)) do
            ::I18n.locale = $1
            ''
          end
          path.sub!(%r{^$}) { '/' }
        else
          ::I18n.locale = ::Refinery::I18n.default_frontend_locale
        end
      end

      yield.tap do |params|
        params[:locale] = ::I18n.locale if ::Refinery::I18n.enabled?
        params
      end
    end

    def around_generate(params, &block)
      locale = params.delete(:locale) || ::I18n.locale

      yield.tap do |result|
        if ::Refinery::I18n.enabled? and
           locale != ::Refinery::I18n.default_frontend_locale and
           result !~ %r{^/(refinery|wymiframe)}
          result.sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{locale}#{$2}" }
        end

        result
      end
    end

  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
refinerycms-i18n-1.0.0 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.16 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.15 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.14 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.13 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.12 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.10 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.9 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.8 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.7 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.6 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.5 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.4 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.3 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.2 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9.1 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.9 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.8.12 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.8.11 lib/refinery/i18n-filter.rb
refinerycms-i18n-0.9.8.8 lib/refinery/i18n-filter.rb