Class: I18n::Backend::SimpleStorage

Inherits:
Simple
  • Object
show all
Defined in:
lib/i18n/backend/simple_storage.rb

Constant Summary collapse

@@sort_keys =
true

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sort_keysObject



14
15
16
# File 'lib/i18n/backend/simple_storage.rb', line 14

def sort_keys
  @@sort_keys
end

.sort_keys=(sort_keys) ⇒ Object



18
19
20
# File 'lib/i18n/backend/simple_storage.rb', line 18

def sort_keys=(sort_keys)
  @@sort_keys = sort_keys
end

Instance Method Details

#copy_translations(from, to) ⇒ Object



33
34
35
36
37
38
# File 'lib/i18n/backend/simple_storage.rb', line 33

def copy_translations(from, to)
  init_translations unless initialized?
  I18n.available_locales.each do |locale|
    store_translations(locale, to => I18n.t(from, :raise => true))
  end
end

#interpolate(locale, original, values = {}) ⇒ Object



23
24
25
26
# File 'lib/i18n/backend/simple_storage.rb', line 23

def interpolate(locale, original, values = {})
  return original unless original.is_a?(String)
  super.tap { |string| set_translation_properties(string, original.properties) }
end

#remove_translation(key) ⇒ Object



40
41
42
43
44
45
# File 'lib/i18n/backend/simple_storage.rb', line 40

def remove_translation(key)
  init_translations unless initialized?
  key = I18n.send(:normalize_translation_keys, nil, key, nil)
  keys = available_locales.map { |locale| [locale] + key }
  translations.delete_nested_if { |k, v| keys.include?(k) }
end

#save_translations(filenames = I18n.load_path.flatten) ⇒ Object



47
48
49
50
51
# File 'lib/i18n/backend/simple_storage.rb', line 47

def save_translations(filenames = I18n.load_path.flatten)
  Array(filenames).each do |filename|
    save_file(filename, by_filename(filename))
  end
end

#store_translations(locale, data) ⇒ Object



28
29
30
31
# File 'lib/i18n/backend/simple_storage.rb', line 28

def store_translations(locale, data)
  data.each_nested { |key, value| raise KeyExists.new(locale, key) if lookup(locale, key) }
  super
end