Sha256: f912e0902139397b2305eab4ec2399b3a98f44427fc07284b100036f60ee8d8e

Contents?: true

Size: 700 Bytes

Versions: 28

Compression:

Stored size: 700 Bytes

Contents

# encoding: utf-8
module WebTranslateIt

  # 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"
  #
  class AutoFetch
    def initialize(app)
      @app = app
    end

    def call(env)
      update_translations if valid_request?(env)
      @app.call(env)
    end

  private

    def update_translations
      WebTranslateIt.fetch_translations
      I18n.reload!
    end

    def valid_request?(env)
      !(env['PATH_INFO'] =~ /\.(js|css|jpeg|jpg|gif|png|woff)$/)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
web_translate_it-2.5.4 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.5.3 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.5.2 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.5.1 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.5.0 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.12 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.11 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.10 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.9 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.8 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.7 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.6 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.5 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.4 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.3 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.2 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.1 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.4.0 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.3.4 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.3.3 lib/web_translate_it/auto_fetch.rb