Sha256: 806d41cf0cff5bebc96ea5ea8e0c6bb238272fcbc1acb1c69aea014e11c7ff28

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module RailsI18nRoutes
  module ActionController
    module Base
        
      def self.included(base)
        base.send :prepend_before_filter, :select_locale
      end
      
      protected
      
      def select_locale
        if Rails.application.config.i18n_routes.selection == :subdomain
          Rails.application.config.i18n_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.i18n_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

2 entries across 2 versions & 1 rubygems

Version Path
rails_i18n_routes-1.1.9 lib/rails_i18n_routes/action_controller/base.rb
rails_i18n_routes-1.1.8 lib/rails_i18n_routes/action_controller/base.rb