Sha256: 23e75055d178c5e27629eca95a199430b8bc78092ebe161c75acc11d99abeadd

Contents?: true

Size: 1.64 KB

Versions: 1

Compression:

Stored size: 1.64 KB

Contents

module I18nAdminUtils
  class TranslationController < ApplicationController
    def index

    end

    def edit
      if params[:key].nil?
        i18n_redirect('No key specified')
      else
        key = params[:key]
        locale = params[:locale]
        value = params[:value]
        if locale.nil?
          if key.include? '.'
            split = key.split('.', 2)
            locale = split[0]
            key = split[1]
          else
            i18n_redirect('No locale specified')
            return
          end
        end
        translation = I18nAdminUtils::Config.translation_model.where(:locale => locale, :key => key).first
        if translation.nil?
          translation = I18nAdminUtils::Config.translation_model.new
          translation.locale = locale
          translation.key = key
        end
        translation.value = value
        translation.save
        I18n.backend.reload! if I18nAdminUtils::Config.reload_translation_after_update
        i18n_redirect('Translation edited with success')
      end
    end

    #Return a list of all the missing translation
    def missing_list
      translation = I18nAdminUtils::SearchTranslation.search
      puts translation
      render :partial => 'missing_list', :layout => false, :locals=> {:translation => translation}
    end

    def i18n_redirect(message, success = true)
      if request.xhr?
        render :json => {:success => success, :message => message}
      else
        if success
          redirect_to :back, :notice => message
        else
          redirect_to :back, :alert => message
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
i18n_admin_utils-0.0.1 app/controllers/i18n_admin_utils/translation_controller.rb