Class: Weeler::TranslationsController

Inherits:
ConfigurationController show all
Defined in:
app/controllers/weeler/translations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/weeler/translations_controller.rb', line 18

def create
  @translation = I18n::Backend::Weeler::Translation.new(translation_params)

  if @translation.save
    Setting.i18n_updated_at = Time.now
    redirect_to ({ action: :edit, id: @translation }), flash: { success: "Translation saved." }
  else
    flash.now[:error] = "Errors in saving."
    render :edit
  end
end

#destroyObject



43
44
45
46
47
48
49
50
# File 'app/controllers/weeler/translations_controller.rb', line 43

def destroy
  @translation = I18n::Backend::Weeler::Translation.find(params[:id])
  @translation.destroy

  Setting.i18n_updated_at = Time.now

  redirect_to ({ action: :index }), flash: {success: "Translation succesfully removed."}
end

#editObject



14
15
16
# File 'app/controllers/weeler/translations_controller.rb', line 14

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

#exportObject



52
53
54
55
56
57
58
59
60
# File 'app/controllers/weeler/translations_controller.rb', line 52

def export
  respond_to do |format|
    format.xlsx do
      outstrio = StringIO.new
      outstrio.write(translations_by_params.as_xlsx_package.to_stream.read)
      send_data(outstrio.string, filename: "translations" + '.xlsx')
    end
  end
end

#importObject



62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/weeler/translations_controller.rb', line 62

def import
  if params[:file].present?
    I18n::Backend::Weeler::Translation.import params[:file]

    Setting.i18n_updated_at = Time.now

    redirect_to ({ action: :index }), flash: {success: "Translations succesfully imported."}
  else
    redirect_to ({ action: :index }), flash: {success: "No file choosen"}
  end
end

#indexObject



4
5
6
7
8
# File 'app/controllers/weeler/translations_controller.rb', line 4

def index
  @translations = translations_by_params
  @translations = @translations.page(params[:page]).per(20)
  @groups = I18n::Backend::Weeler::Translation.groups
end

#newObject



10
11
12
# File 'app/controllers/weeler/translations_controller.rb', line 10

def new
  @translation = I18n::Backend::Weeler::Translation.new
end

#updateObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/weeler/translations_controller.rb', line 30

def update
  @translation = I18n::Backend::Weeler::Translation.find(params[:id])

  if @translation.update(translation_params)
    Setting.i18n_updated_at = Time.now

    redirect_to ({ action: :edit, id: @translation }), flash: { success: "Translation updated." }
  else
    flash.now[:error] = "Errors in updating."
    render :edit
  end
end