Module: I18n::Backend::GlobalizeStore::Implementation

Includes:
Base, Flatten
Included in:
I18n::Backend::GlobalizeStore
Defined in:
lib/exvo_globalize/backend/globalize_store.rb

Instance Method Summary collapse

Methods included from Flatten

#nest_translations

Instance Method Details

#available_localesObject



12
13
14
# File 'lib/exvo_globalize/backend/globalize_store.rb', line 12

def available_locales
  GlobalizeTranslation.available_locales
end

#available_translations(locale = nil) ⇒ Object

returns a nested Hash with all translations { :en => { :hello => { :world => “Hello world”, :earth => “Hello Earth” } } } …



18
19
20
21
22
23
24
# File 'lib/exvo_globalize/backend/globalize_store.rb', line 18

def available_translations(locale = nil)
  translations = locale.present? ? GlobalizeTranslation.where(:locale => locale).ordered : GlobalizeTranslation.ordered

  translations.inject({}) do |result, element|
    result.deep_merge( { element["locale"].to_sym => nest_translations(element["key"] => element["value"]) } )
  end
end

#store_flatten_translation(locale, key, value) ⇒ Object



33
34
35
36
# File 'lib/exvo_globalize/backend/globalize_store.rb', line 33

def store_flatten_translation(locale, key, value)
  GlobalizeTranslation.where(:locale => locale).lookup(expand_keys(key)).delete_all
  GlobalizeTranslation.create(:locale => locale.to_s, :key => key.to_s, :value => value)
end

#store_translations(locale, data, options = {}) ⇒ Object



26
27
28
29
30
31
# File 'lib/exvo_globalize/backend/globalize_store.rb', line 26

def store_translations(locale, data, options = {})
  escape = options.fetch(:escape, true)
  flatten_translations(locale, data, escape, false).each do |key, value|
    store_flatten_translation(locale, key, value)
  end
end