Class: GlobalizeTranslationsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/globalize_translations_controller.rb

Instance Method Summary collapse

Instance Method Details

#listObject



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

def list
  @languages = I18n.backend.available_locales.sort_by(&:to_s)

  hash = case params[:type]
    when "yaml-app"
      I18n.backend.available_app_translations
    when "yaml"
      I18n.backend.simple.available_translations
    when "db"
      I18n.backend.globalize_store.available_translations
    else
      I18n.backend.available_translations
    end

  @translations = params[:locale].present? ? { params[:locale].to_sym => hash[params[:locale].to_sym] } : hash
end

#showObject



10
11
12
13
14
15
16
17
18
# File 'app/controllers/globalize_translations_controller.rb', line 10

def show
  @translations = if params[:id].present?
      I18n.backend.available_translations_scoped_by_locale_with_default(params[:id].to_sym)
    else
      I18n.backend.available_app_translations.merge({ :default_locale => I18n.default_locale })
    end

  respond_with @translations
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/globalize_translations_controller.rb', line 37

def update
  translations = @globalize_app.fetch_translations

  if translations.present? and !translations.has_key?("errors")
    if I18n.backend.store_nested_translations(translations)
      flash.now[:notice] = 'Translations updated'
    else
      flash.now[:alert] = 'There was a problem while updating translations'
    end
  else
    flash.now[:alert] = "There was a problem while fetching translations: #{translations["errors"].to_s.downcase}"
  end

  render :show
end