Class: Sprockets::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n/assets/sprockets.rb

Instance Method Summary collapse

Instance Method Details

#cache_key_for(path, options) ⇒ Object

add locale to assets cache key



104
105
106
# File 'lib/i18n/assets/sprockets.rb', line 104

def cache_key_for(path, options)
  "#{path}:#{I18n.locale}:#{options[:bundle] ? '1' : '0'}"
end

#call(env) ⇒ Object

set locale for asset request



96
97
98
99
100
101
# File 'lib/i18n/assets/sprockets.rb', line 96

def call(env)
  locale = extract_locale(env['PATH_INFO'])
  env['PATH_INFO'].gsub!(Regexp.new("^/#{ locale }"), '') if locale
  I18n.locale = Rack::Request.new(env).params['locale'] || locale || I18n.default_locale
  super
end