Sha256: 1543567905dd84f53a11a73542161245de963964e436af2c2c0071292df7dfb5

Contents?: true

Size: 757 Bytes

Versions: 4

Compression:

Stored size: 757 Bytes

Contents

module Champollion
  class Translation < ActiveRecord::Base
    self.table_name = "translations"

    has_paper_trail

    validates :locale, presence: true
    validates :key, presence: true
    validates :value, presence: true

    def self.all_translations
      # create empty hash for locales
      translation_hash = Hash.new { |k,v| k[v] = {} }

      # iterate through the translation records
      all.each do |translation|
        # get the key components
        key_scopes = translation.key.split(".")

        translation_hash[translation.locale.to_sym] ||= {}
        translation_hash[translation.locale.to_sym].merge!(key_scopes.reverse.inject(translation.value) {|a,n| { n.to_sym => a}})
      end

      translation_hash 
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
champollion-0.1.5 app/models/champollion/translation.rb
champollion-0.1.2 app/models/champollion/translation.rb
champollion-0.1.1 app/models/champollion/translation.rb
champollion-0.1.0 app/models/champollion/translation.rb