Sha256: 9f071696099669d332b4949cef3d5f1a3103f157967bb642d55134293d587bc0

Contents?: true

Size: 1.72 KB

Versions: 6

Compression:

Stored size: 1.72 KB

Contents

class Lolita::I18nController < ApplicationController
  include Lolita::ControllerAdditions
  before_filter :authenticate_lolita_user!, :set_current_locale

  layout "lolita/application"

  def index
    authorization_proxy.authorize!(:read, self.resource_class)
    @translations = i18n_request.translations(@active_locale)

    if params[:sort] && params[:sort].to_s == "1"
      @translations = i18n_request.sort_translations(@translations)
    end
  end

  def update
    authorization_proxy.authorize!(:update, self.resource_class)
    respond_to do |format|
      format.json do
        begin
          if saved = i18n_request.update_key 
            notice(::I18n.t("lolita-i18n.Successful update"))
          else
            error(::I18n.t("lolita-i18n.Error"))
          end
          render :nothing => true, :json => {error: !saved && ::I18n.t("lolita-i18n.Error") }
        rescue Lolita::I18n::Exceptions::MissingInterpolationArgument => er
          render :nothing => true, :json => {error: er.to_s}
        rescue Exception => e
          render :nothing => true, :json => {error: "Key is not saved. Some error accured." }
        end
      end
    end
  end

  private
  
  def lolita_mapping
    Lolita.mappings[:i18n]
  end

  def next_locale
    ::I18n::available_locales.collect{|locale| locale if locale != ::I18n.default_locale}.compact.first
  end

  def set_current_locale
    @active_locale = ::I18n.available_locales.include?(params[:active_locale].to_s.to_sym) ? params[:active_locale] : nil
    @active_locale ||= next_locale
    @active_locale = @active_locale.to_sym
    @active_locale = nil if @active_locale == ::I18n.default_locale
  end

  def i18n_request
    @i18n_request ||= Lolita::I18n::Request.new(params)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lolita-i18n-0.5.3 app/controllers/lolita/i18n_controller.rb
lolita-i18n-0.5.2 app/controllers/lolita/i18n_controller.rb
lolita-i18n-0.5.1 app/controllers/lolita/i18n_controller.rb
lolita-i18n-0.4.3 app/controllers/lolita/i18n_controller.rb
lolita-i18n-0.4.2 app/controllers/lolita/i18n_controller.rb
lolita-i18n-0.4.0 app/controllers/lolita/i18n_controller.rb