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



21
22
23
24
# File 'app/controllers/rails_i18nterface/translate_controller.rb', line 21

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

#exportObject



26
27
28
29
30
31
32
33
# File 'app/controllers/rails_i18nterface/translate_controller.rb', line 26

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



11
12
13
14
15
16
17
18
19
# File 'app/controllers/rails_i18nterface/translate_controller.rb', line 11

def index
  @dbvalues = {}
  @keys = RailsI18nterface::Keys.new(Rails.root, @from_locale, @to_locale)
  @keys.apply_filters(params)
  paginate_keys
  @total_entries = @keys.all_keys.size
  @page_title = 'Translate'
  @show_filters = ['all', 'untranslated', 'translated']
end

#reloadObject



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

def reload
  @keys.reload
  redirect_to root_path(params.slice(:filter, :sort_by, :key_type, :key_pattern, :text_type, :text_pattern))
end

#updateObject



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

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'
  redirect_to root_path(params.slice(:filter, :sort_by, :key_type, :key_pattern, :text_type, :text_pattern))
end