Sha256: 837c9961e50c6e3a1579713de1345eac89393b0722cd8c4727a938b114b5ef38

Contents?: true

Size: 1.39 KB

Versions: 10

Compression:

Stored size: 1.39 KB

Contents

module RoutingFilter
  class Locale < Base

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

        returning yield do |params|
          unless path =~ %r{^/(admin|refinery|wymiframe)} or ::I18n.locale == ::Refinery::I18n.default_frontend_locale
            params[:locale] = (locale.presence || ::Refinery::I18n.current_frontend_locale)
          end
        end
      else
        returning yield do |result|
          result
        end
      end
    end

    def around_generate(*args, &block)
      if ::Refinery::I18n.enabled?
        locale = args.extract_options!.delete(:locale) || ::I18n.locale
        returning yield do |result|
          if (locale != ::Refinery::I18n.default_frontend_locale and result !~ %r{^/(refinery|wymiframe)})
            result.sub!(%r(^(http.?://[^/]*)?(.*))){ "#{$1}/#{locale}#{$2}" }
          end
          result
        end
      else
        returning yield do |result|
          result
        end
      end
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
refinerycms-0.9.7.14 vendor/plugins/i18n/lib/i18n_filter.rb
refinerycms-0.9.7.13 vendor/plugins/i18n/lib/i18n_filter.rb
refinerycms-0.9.7.11 vendor/plugins/i18n/lib/i18n_filter.rb
refinerycms-0.9.7.10 vendor/plugins/i18n/lib/i18n_filter.rb
refinerycms-0.9.7.9 vendor/plugins/i18n/lib/i18n_filter.rb
refinerycms-0.9.7.8 vendor/plugins/i18n/lib/i18n_filter.rb
refinerycms-0.9.7.7 vendor/plugins/i18n/lib/i18n_filter.rb
refinerycms-0.9.7.6 vendor/plugins/i18n/lib/i18n_filter.rb
refinerycms-0.9.7.5 vendor/plugins/i18n/lib/i18n_filter.rb
refinerycms-0.9.7.4 vendor/plugins/i18n/lib/i18n_filter.rb