Sha256: fb179c3c36dad88873552939f02ace420084eaa5b51018cacfadd7acc2ed3ae3

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

require 'active_support'

module Rails
  module Localization
    module RoutesExt
      extend ActiveSupport::Concern

      included do
        def generate_with_locale
          locale = options.delete(:locale)
          path, params = generate_without_locale
          if locale != false #only in case of :locale => false ignore the block below
            path = localized_path(path, (locale || ::I18n.locale))
          end
          [path, params]
        end
        alias_method_chain :generate, :locale

        private

        def localized_path path, locale
          raise Rails::Localization::UnknownLocaleError.new("Not supported locale: #{locale}. If this locale should be \
supported, add it to Middelware (#{Rails.root.join('config','application.rb')})") unless Rails::Localization::Middleware.languages.include?(locale.to_s)
          locale.to_sym == ::I18n.default_locale ? path : "/#{locale}#{path}"
        end
      end
    end
  end
end

ActiveSupport.on_load(:before_initialize) do
  ActionDispatch::Routing::RouteSet::Generator.send :include, Rails::Localization::RoutesExt
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rails-localization-0.1.1 lib/rails-localization/routes_ext.rb
rails-localization-0.1.0 lib/rails-localization/routes_ext.rb