Sha256: d3b16a1e6d216a28564301c7fe645a93025b11a3ea49e538218432fd6a03f23c

Contents?: true

Size: 680 Bytes

Versions: 5

Compression:

Stored size: 680 Bytes

Contents

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

5 entries across 5 versions & 1 rubygems

Version Path
web_translate_it-2.6.3 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.6.3.pre1 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.6.2 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.6.1 lib/web_translate_it/auto_fetch.rb
web_translate_it-2.6.0 lib/web_translate_it/auto_fetch.rb