Sha256: 317ce4838a4db3294de07d997c154d2851954da624258459a23e1e41c0ec14c4

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

class GlobalizeTranslationsController < ApplicationController

  before_filter :globalize_translations_authenticator
  before_filter :set_globalize_app

  layout 'exvo_globalize'

  respond_to :html, :json

  def show
    # returns {"default_locale":"en","pl":{"hello.world":"Witaj \u015bwiecie","hello.earth":"Witaj ziemio"},"en":{"hello.world":"Hello world","hello.earth":"Hello Earth"}}
    @translations = I18n.backend.available_translations.merge({ :default_locale => I18n.default_locale })
    respond_with @translations
  end

  def update
    if I18n.backend.store_flatten_translations(@globalize_app.fetch_translations)
      flash.now[:notice] = 'Translations updated'
    else
      flash.now[:alert] = 'There was a problem while updating translations'
    end
    render :show
  end

  private

  def globalize_translations_authenticator
    # get :show as JSON does not require authentication
    return if params[:action].to_s == 'show' and request.format.json?

    # call custom authenticator method if available
    if I18n::Backend::GlobalizeStore.authenticator && I18n::Backend::GlobalizeStore.authenticator.respond_to?(:call)
      I18n::Backend::GlobalizeStore.authenticator.bind(self).call
    end
  end

  def set_globalize_app
    @globalize_app ||= GlobalizeApp.new(ENV["GLOBALIZE_REQUEST_HOST"] || request.host)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
exvo_globalize-0.2.1 app/controllers/globalize_translations_controller.rb
exvo_globalize-0.2.0 app/controllers/globalize_translations_controller.rb
exvo_globalize-0.1.0 app/controllers/globalize_translations_controller.rb