Class: Burek::TranslationsStore
- Inherits:
-
Object
- Object
- Burek::TranslationsStore
- Defined in:
- lib/core/translations_store.rb
Instance Method Summary collapse
- #get_hash ⇒ Object
-
#initialize(translations_hash = {}) ⇒ TranslationsStore
constructor
A new instance of TranslationsStore.
- #load_locale(locale, file_path) ⇒ Object
- #push_call(call) ⇒ Object
- #save_locale(locale, file_path) ⇒ Object
Constructor Details
#initialize(translations_hash = {}) ⇒ TranslationsStore
Returns a new instance of TranslationsStore.
5 6 7 |
# File 'lib/core/translations_store.rb', line 5 def initialize(translations_hash={}) @translations_hash = translations_hash end |
Instance Method Details
#get_hash ⇒ Object
45 46 47 |
# File 'lib/core/translations_store.rb', line 45 def get_hash @translations_hash end |
#load_locale(locale, file_path) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/core/translations_store.rb', line 9 def load_locale(locale, file_path) locale = locale.to_s if File.exists?(file_path) @translations_hash = YAML::load_file(file_path) #Load else @translations_hash[locale] = {} end end |
#push_call(call) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/core/translations_store.rb', line 25 def push_call(call) Burek.config.get(:locales).each do |locale| # In case it's a symbole convert it to string locale = locale.to_s # Initialize hash for current locale @translations_hash[locale] = {} unless @translations_hash.has_key?(locale) # Nest hash cur_hash = @translations_hash[locale] call.parent_key_array.each do |item| cur_hash[item] = {} unless cur_hash.has_key?(item) cur_hash = cur_hash[item] end cur_hash[call.key] = call.translation(locale) end end |
#save_locale(locale, file_path) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/core/translations_store.rb', line 18 def save_locale(locale, file_path) locale = locale.to_s File.open(file_path, "w:UTF-8") do |f| f.write locale_yaml(locale) end end |