Sha256: ec9876366f0b426ca106660725bc75de29980414e6eedaf472e7a87d5bfd56d4

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module Kakimasu
  class TranslationsController < ::ApplicationController
    # Include neccessary helpers
    include PaginationHelper

    def index
      # Authorization
      authorize :translation, :index?
      policy_scope(Translation)

      @translations = TRANSLATION_STORE                                                  # Gets all translations from redis
      @grouped_keys = @translations.keys.group_by { |key| key.partition('.').last }      # Groups all translations by key
      @active_tab = 'translations'                                                       # Sets active tab in navigation

      set_page_size(10)                            # set number of keys in one page
      params[:page] = 1 unless params[:page]      # if page number is not stated, then by default it is 1. page
    end

    def create
      authorize :translation, :create?
      I18n.available_locales.each do |l|
        params[l]&.gsub!("'", "&#39;")
        I18n.backend.store_translations(l, { params[:key] => params[l] }, escape: false) unless params[l].blank?
      end
      params[:value]&.gsub!("'", "&#39;")
      I18n.backend.store_translations(params[:language], { params[:key] => params[:value] }, escape: false) if params[:language]

      if request.xhr?
        respond_to do |format|
          format.js {}
        end
      else
        redirect_to :back
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kakimasu-1.0.0 app/controllers/kakimasu/translations_controller.rb