class WebTranslateIt::AutoFetch
Class to automatically fetch the last translations from Web Translate It for every page requested. This can be used as a rack middleware. Implementation example:
# in config/environment.rb: config.middleware.use "WebTranslateIt::AutoFetch"
Public Class Methods
new(app)
click to toggle source
# File lib/web_translate_it/auto_fetch.rb, line 15 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/web_translate_it/auto_fetch.rb, line 19 def call(env) update_translations if valid_request?(env) @app.call(env) end
Private Instance Methods
update_translations()
click to toggle source
# File lib/web_translate_it/auto_fetch.rb, line 26 def update_translations WebTranslateIt.fetch_translations I18n.reload! end
valid_request?(env)
click to toggle source
# File lib/web_translate_it/auto_fetch.rb, line 31 def valid_request?(env) env['PATH_INFO'] !~ /\.(js|css|jpeg|jpg|gif|png|woff)$/ end