Class: RailsI18nterface::TranslateController

Inherits:
ApplicationController show all
Includes:
Utils
Defined in:
app/controllers/rails_i18nterface/translate_controller.rb

Instance Method Summary collapse

Methods included from Utils

#contains_key?, #deep_merge!, #deep_sort, #deep_stringify_keys, #keys_to_yaml, #remove_blanks, #set_nested, #to_deep_hash, #to_shallow_hash

Instance Method Details

#destroyObject



18
19
20
21
# File 'app/controllers/rails_i18nterface/translate_controller.rb', line 18

def destroy
  params[:key] = { params[:del] => '' }
  update
end

#exportObject



23
24
25
26
27
28
29
30
# File 'app/controllers/rails_i18nterface/translate_controller.rb', line 23

def export
  locale = params[:locale].to_sym
  keys = { locale => I18n.backend.send(:translations)[locale] || {} }
  remove_blanks keys
  yaml = keys_to_yaml(keys)
  response.headers['Content-Disposition'] = "attachment; filename=#{locale}.yml"
  render text: yaml
end

#indexObject



9
10
11
12
13
14
15
16
# File 'app/controllers/rails_i18nterface/translate_controller.rb', line 9

def index
  @keys = RailsI18nterface::Keys.new(Rails.root, @from_locale, @to_locale)
  @keys.apply_filters(params)
  @keys.paginate(@page, @per_page)
  @total_entries = @keys.all_keys.size
  @page_title = 'Translate'
  @show_filters = %w(all untranslated translated)
end

#reloadObject



44
45
46
47
48
# File 'app/controllers/rails_i18nterface/translate_controller.rb', line 44

def reload
  @keys = RailsI18nterface::Keys.new(Rails.root, @from_locale, @to_locale)
  @keys.reload(Rails.root)
  redirect_to root_path(params.slice(:filter, :sort_by, :key_type, :key_pattern, :text_type, :text_pattern))
end

#updateObject



32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/rails_i18nterface/translate_controller.rb', line 32

def update
  if I18n.backend.respond_to? :store_translations
    I18n.backend.store_translations(@to_locale, to_deep_hash(params[:key]))
  end
  yaml = RailsI18nterface::Yamlfile.new(Rails.root, @to_locale)
  yaml.write_to_file
  force_init_translations
  flash[:notice] = 'Translations stored'
  reload
  # redirect_to root_path(params.slice(:filter, :sort_by, :key_type, :key_pattern, :text_type, :text_pattern))
end