Sha256: 8f923acfdb99b4b09d3a9cb2635aaf611274dd859b6b9eb19b37fd3112f3dd14

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

class Interpret::TranslationsController < Interpret::BaseController
  cache_sweeper eval(Interpret.sweeper.to_s.classify) if Interpret.sweeper
  cache_sweeper Interpret::TranslationSweeper
  before_filter :get_tree, :only => :index

  def index
    key = params[:key]
    t = Interpret::Translation.arel_table
    if key
      @translations = Interpret::Translation.locale(I18n.locale).where(t[:key].matches("#{key}.%"))
      @translations = @translations.select{|x| x.key =~ /#{key}\.\w+$/}
    else
      @translations = Interpret::Translation.locale(I18n.locale).where(t[:key].does_not_match("%.%")).paginate :page => params[:page]
    end
  end

  def edit
    @translation = Interpret::Translation.find(params[:id])
  end

  def update
    @translation = Interpret::Translation.find(params[:id])
    old_value = @translation.value

    respond_to do |format|
      if @translation.update_attributes(params[:interpret_translation])
        msg = respond_to?(:current_user) ? "By [#{current_user}]. " : ""
        msg << "Locale: [#{@translation.locale}], key: [#{@translation.key}]. The translation has been changed from [#{old_value}] to [#{@translation.value}]"
        Interpret.logger.info msg

        format.html { redirect_to(translations_url)}
        format.xml  { head :ok }
        format.json { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @translation.errors, :status => :unprocessable_entity }
        format.json { render :status => :unprocessable_entity }
      end
    end
  end

private
  def get_tree
    @tree = session[:tree] ||= Interpret::Translation.get_tree
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
interpret-0.1.3 app/controllers/interpret/translations_controller.rb
interpret-0.1.2 app/controllers/interpret/translations_controller.rb
interpret-0.1.1 app/controllers/interpret/translations_controller.rb