Class: Interpret::MissingTranslationsController

Inherits:
BaseController show all
Defined in:
app/controllers/interpret/missing_translations_controller.rb

Instance Method Summary collapse

Instance Method Details

#blankObject



23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/interpret/missing_translations_controller.rb', line 23

def blank
  authorize! :read, :blank_translations
  @blank_translations = Interpret::Translation.allowed.locale(I18n.locale).where(:value => "--- \"\"\n")
  @ref_translations = Interpret::Translation.allowed.locale(I18n.default_locale).where(:key => @blank_translations.map{|x| x.key})

  @blank_translations.map do |x|
    foo = @ref_translations.detect{|y| x.key == y.key}
    [x, foo ? foo.value : nil]
  end
end

#indexObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/interpret/missing_translations_controller.rb', line 2

def index
  authorize! :read, :missing_translations
  return if I18n.locale == I18n.default_locale

  case ActiveRecord::Base.connection.adapter_name
  when "Mysql2"
    res = ActiveRecord::Base.connection.execute("select t.id from translations t where t.locale ='#{I18n.default_locale}' and (select count(*) from translations t2 where t2.key = t.key and t2.locale ='#{I18n.locale}') = 0")

  when "SQLite"
    res = ActiveRecord::Base.connection.execute("select t.id from translations t where t.locale ='#{I18n.default_locale}' and (select count(*) from translations t2 where t2.key = t.key and t2.locale ='#{I18n.locale}') = 0")

  else
    raise NotImplementedError, "database adapter not supported"
  end

  ids = res.map{|x| x.first}
  translations = Interpret::Translation.allowed.where(:id => ids).order("translations.key ASC").all
  translations = translations.select{|x| x.value.present?}
  @missing_translations = translations.map{|x| {:ref_value => x.value, :key => x.key, :source => x}}
end

#staleObject



40
41
42
43
44
45
# File 'app/controllers/interpret/missing_translations_controller.rb', line 40

def stale
  authorize! :read, :stale_translations
  @stale_translations = Interpret::Translation.allowed.stale.locale(I18n.locale).order("translations.key ASC")
  refs = Interpret::Translation.locale(I18n.default_locale).where(:key => @stale_translations.map{|x| x.key})
  @stale_translations.map!{|x| [x, refs.detect{|y| y.key == x.key}]}
end

#unusedObject



34
35
36
37
38
# File 'app/controllers/interpret/missing_translations_controller.rb', line 34

def unused
  authorize! :read, :unused_translations
  used_keys = Interpret::Translation.allowed.locale(I18n.default_locale).all.map{|x| x.key}
  @unused_translations = Interpret::Translation.allowed.locale(I18n.locale).where("translations.key NOT IN (?)", used_keys)
end