Module: Localized::Convert
- Defined in:
- lib/localized/convert.rb
Class Method Summary collapse
Class Method Details
.load_cache ⇒ Object
18 19 20 |
# File 'lib/localized/convert.rb', line 18 def self.load_cache I18n.backend.send(:init_translations) end |
.locale_cache ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/localized/convert.rb', line 27 def self.locale_cache @locale_cache = begin rows = {} columns = Hash[locale_columns.map{|l| [l, nil]}] Localized::Config.supported_locales.each do |locale| # each locale formalize_keys(nil, (translations[locale] || {})).each do |(key, value)| # each translation rows[key] ||= columns rows[key] = rows[key].merge(locale => value) end end rows.reject { |k, r| r.values.compact.blank? } end end |
.to_csv(file) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/localized/convert.rb', line 4 def self.to_csv(file) CSV.open(file, "wb") do |csv| csv << ["Token", *locale_columns] locale_cache.keys.sort.each do |token| row = [token] locale_columns.each do |locale| row << locale_cache[token][locale] end csv << row end end nil end |
.translations ⇒ Object
22 23 24 25 |
# File 'lib/localized/convert.rb', line 22 def self.translations load_cache @translations ||= I18n.backend.send(:translations) end |