Sha256: 09cafeec0eb6cd3547602a32041692a140ec883cb7931755b169345093ae0703

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module TranslatableRoutes
  module ActionController
    module Base
      extend ActiveSupport::Concern
        
      included do
        prepend_before_filter :select_locale
      end
      
      protected
      
      def select_locale
        if Rails.application.config.translatable_routes.selection == :subdomain
          Rails.application.config.translatable_routes.mapping.each_pair do |key, value|
            if (value.is_a? Array and value.include? request.subdomain.to_sym) or value == request.subdomain.to_sym
              I18n.locale = "#{key}-#{request.subdomain.upcase}" 
              break
            end
          end
        elsif not params[:locale].nil?
          I18n.locale = params[:locale] 
        end       
      end
      
      def subdomains
        @subdomains ||= begin
          values = []
          Rails.application.config.translatable_routes.mapping.values.each do |value|
            value = [value] unless value.is_a? Array
            values.concat value
          end
          values
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
translatable_routes-1.2.0 lib/translatable_routes/action_controller/base.rb