Module: Translator

Defined in:
lib/translator.rb,
lib/translator/engine.rb,
app/backends/translator/redis_store.rb,
app/backends/translator/mongo_store.rb,
app/controllers/translator/translations_controller.rb

Defined Under Namespace

Classes: Engine, MongoStore, RedisStore, TranslationsController

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.auth_handlerObject

Returns the value of attribute auth_handler


5
6
7
# File 'lib/translator.rb', line 5

def auth_handler
  @auth_handler
end

.current_storeObject

Returns the value of attribute current_store


5
6
7
# File 'lib/translator.rb', line 5

def current_store
  @current_store
end

.framework_keysObject

Returns the value of attribute framework_keys


5
6
7
# File 'lib/translator.rb', line 5

def framework_keys
  @framework_keys
end

.layout_nameObject


81
82
83
# File 'lib/translator.rb', line 81

def self.layout_name
  @layout_name || "translator"
end

.simple_backendObject (readonly)

Returns the value of attribute simple_backend


6
7
8
# File 'lib/translator.rb', line 6

def simple_backend
  @simple_backend
end

Class Method Details

.keys_for_strings(options = {}) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/translator.rb', line 53

def self.keys_for_strings(options = {})
  @simple_backend.available_locales

  flat_translations = {}
  flatten_keys nil, Translator.get_translations, flat_translations
  flat_translations = flat_translations.delete_if {|k,v| !v.is_a?(String) }
  store_keys = Translator.current_store.keys.map {|k| k.sub(/^[a-z0-9\-_]*\./i, '')}

  keys = if options[:group].to_s == "deleted"
    store_keys - flat_translations.keys
  else
    store_keys + flat_translations.keys
  end.uniq

  if options[:filter]
    keys = keys.select {|k| k[0, options[:filter].size] == options[:filter]}
  end

  case options[:group].to_s
  when "framework"
    keys.select! {|k| @framework_keys.include?(k) }
  when "application"
    keys -= @framework_keys
  end

  keys || []
end

.localesObject


49
50
51
# File 'lib/translator.rb', line 49

def self.locales
  @simple_backend.available_locales
end

.setup_backend(simple_backend) ⇒ Object


43
44
45
46
47
# File 'lib/translator.rb', line 43

def self.setup_backend(simple_backend)
  @simple_backend = simple_backend

  I18n::Backend::Chain.new(I18n::Backend::KeyValue.new(@current_store), @simple_backend)
end