Sha256: 75aebbc9e06348b0c945ae93a37b73c5c626c3b5f1724ce272c5f4b5d112dde2

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

def upload_locale(upload_bundle = nil)
  require 'v8'

  def traverse_terms terms, category, cxt
    terms.each do |name, value|
      if value.is_a? String
        if name.ends_with?('.short')
          Terminology.where({
            domain_id: Domain.current_domain.id,
            name: name[0..-7],
            locale: cxt['locale'],
            category: category
          }).first_or_create.update({
            display_short: value
          })
        else
          Terminology.where({
            domain_id: Domain.current_domain.id,
            name: name,
            locale: cxt['locale'],
            category: category
          }).first_or_create.update({
            display: value
          })
        end
  
      else
        traverse_terms value, name, cxt
      end
    end
  end  

  V8::Context.new do |cxt|
    
    cxt['T'] = lambda do |this, terms|
      traverse_terms terms, 'global', cxt
    end

    Hatio::Bundle.ordered_bundle_list.each do |bundle|
      bundle_name = bundle.name
      
      next if(upload_bundle && upload_bundle != bundle_name)
  
      spec = Gem::Specification.find_by_name(bundle_name)
      gem_root = spec.gem_dir

      Dir[gem_root + '/app/assets/javascripts/**/locale/??-??.js'].each do |termfile|
        puts "[LOCALE FILE] #{termfile}"
        locale = termfile.split('/').last.split('.').first

        cxt['locale'] = locale

        cxt.load(termfile);
      end
    end
    
    Dir[Rails.root.to_path + '/app/assets/javascripts/**/locale/??-??.js'].each do |termfile|
      puts "[LOCALE FILE] #{termfile}"
      locale = termfile.split('/').last.split('.').first
    
      cxt['locale'] = locale
    
      cxt.load(termfile);
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hatio-core-0.0.6 lib/utils/upload_locale.rb