Class: Kakimasu::TranslationsController

Inherits:
ApplicationController
  • Object
show all
Includes:
PaginationHelper
Defined in:
app/controllers/kakimasu/translations_controller.rb

Instance Method Summary collapse

Methods included from PaginationHelper

#get_page_size, #set_page_size, #total_pages

Instance Method Details

#createObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/kakimasu/translations_controller.rb', line 19

def create
  authorize :translation, :create?
  I18n.available_locales.each do |l|
    params[l]&.gsub!("'", "'")
    I18n.backend.store_translations(l, { params[:key] => params[l] }, escape: false) unless params[l].blank?
  end
  params[:value]&.gsub!("'", "'")
  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

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/kakimasu/translations_controller.rb', line 6

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