Module: HolaMilindPatel

Defined in:
lib/hola_milind_patel.rb

Class Method Summary collapse

Class Method Details

.getData(data) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hola_milind_patel.rb', line 11

def self.getData(data)
  if RequestStore.store[:selected_language] == "all"
    centers = data.as_json
    centers.map do |center|
      c1 = data.klass.find(center['id'])
        c1.as_json.each do |key,value|
          if (c1.send("#{key}_backend") rescue "false") != "false"
            concat_attribute = key + "_backend"
            c1.send(concat_attribute.parameterize.underscore.to_sym).locales.each do |locale|
              center["#{key}_#{locale}"] = c1.send("#{key}_backend").read(locale)
            end
          end
        end
      center
    end
  else
    centers = data.as_json      
    centers.map do |center|
      center.as_json.each do |key,value|
        record = data.klass.find(center['id'])
        if (record.send("#{key}_backend") rescue "false") != "false"
          if record.send("#{key}_backend").locales.include?(RequestStore.store[:selected_language].parameterize.underscore.to_sym)
            center[key] = record.send("#{key}_backend").read(RequestStore.store[:selected_language].parameterize.underscore.to_sym)
          else
            center[key] = RequestStore.store[:strict] == "true" ? nil : center[key] = record.send("#{key}_backend").read(record.default_language.parameterize.underscore.to_sym)
          end
        end
      end
      center
    end 
  end
  return centers
end

.getShowData(data) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/hola_milind_patel.rb', line 45

def self.getShowData(data)
  if RequestStore.store[:selected_language] == "all"
    center = data
    c = center.as_json
    center.as_json.each do |key,value|        
      if (center.send("#{key}_backend") rescue "false") != "false"
        concat_attribute = key + "_backend"
        center.send(concat_attribute.parameterize.underscore.to_sym).locales.each do |locale|                   
          c["#{key}_#{locale}"] = center.send("#{key}_backend").read(locale)
        end
      end
    end
    return c
  else
    center = data.as_json      
    center.each do |key,value|
      if (data.send("#{key}_backend") rescue "false") != "false"
        obj = JSON.parse(center.to_json,object_class: data.class)
        if obj.send("#{key}_backend").locales.include?(RequestStore.store[:selected_language].parameterize.underscore.to_sym)
          center[key] = obj.send("#{key}_backend").read(RequestStore.store[:selected_language].parameterize.underscore.to_sym)
        else
          center[key] = RequestStore.store[:strict] == "true" ? nil : center[key] = obj.send("#{key}_backend").read(obj.default_language.parameterize.underscore.to_sym)
        end
      end
    end      
    return center
  end
end

.language=(language) ⇒ Object



84
85
86
87
# File 'lib/hola_milind_patel.rb', line 84

def self.language=(language)    
  RequestStore.store[:selected_language] = language
  HolaMilindPatel.locale = language == "all" ?  I18n.default_locale : language
end

.locale=(locale) ⇒ Object



75
76
77
# File 'lib/hola_milind_patel.rb', line 75

def locale=(locale)
  Mobility.locale = locale || I18n.default_locale
end

.strict=(strict) ⇒ Object



80
81
82
# File 'lib/hola_milind_patel.rb', line 80

def self.strict=(strict)
  RequestStore.store[:strict] = strict.present? ? strict : false
end

.translate(data) ⇒ Object



5
6
7
8
9
# File 'lib/hola_milind_patel.rb', line 5

def self.translate(data)
  responce = getData(data) if !data[0].nil?
  responce = getShowData(data) if data[0].nil?
  return responce
end