Sha256: 1401c0debc75f87a3bbde88dc36ac258116e28547219c6b92867e3edb890a88d

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

module RoutingFilter
  class RefineryLocales < Filter

    def around_recognize(path, env, &block)
      if ::Refinery::I18n.url_filter_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.to_s
      end
    end

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

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

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
refinerycms-i18n-5.0.1 lib/refinery/i18n-filter.rb
refinerycms-i18n-5.0.0 lib/refinery/i18n-filter.rb
refinerycms-i18n-4.0.2 lib/refinery/i18n-filter.rb
refinerycms-i18n-4.0.1 lib/refinery/i18n-filter.rb