Class: Xforum::Translation

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/xforum/translation.rb

Class Method Summary collapse

Class Method Details

.add_one(params, topic_id, user_id, forum_id) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/xforum/translation.rb', line 75

def self.add_one(params,topic_id,user_id,forum_id)
  unless params[:translation] == ''
    if PeopleList.check_people({topic:topic_id,list:'moderator',user_id:user_id})  && !Translation.where(language_id:Language.get_me(params),forum_id:params[:id]).nil?
      Translation.where(forum_id:forum_id,topic_id:topic_id, language_id:Language.get_me(params)).update_all(content:params[:translation],suggestion:false,state:'open')
      Translation.where(forum_id:params[:id],topic_id:topic_id,suggestion:true).update_all(state:'closed')
    else
      suggestion = !Translation.where(language_id:Language.get_me(params),forum_id:forum_id).nil?
      Translation.create(forum_id:forum_id,user_id:user_id,topic_id:topic_id, language_id:Language.get_me(params), content:params[:translation],suggestion:suggestion,state:'new')
    end
  end
end

.get_localized_forum(language, params) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/xforum/translation.rb', line 31

def self.get_localized_forum(language,params)
  return  if params.nil?
  plucking=ForumAssist.make_string_list(params[:plucking])
  ordering=ForumAssist.make_string_list(params[:ordering]) unless params[:ordering].nil?
  params[:ordering].nil? ?
    alist=Forum.where(params[:lookup]).pluck(plucking) :
    alist= Forum.where(params[:lookup]).order(ordering).pluck(plucking)
  unless alist.empty?
    indexes=plucking.split(',')
    content=indexes.index('content')
    language_list=Language.where(active:true).order(:code).pluck(:id,:name)
    language_list=ForumAssist.named_array(language_list,[:id,:item])
    if alist.is_a?(Array)
      alist.each { |a_entry|
        entry=ForumAssist.named_array(a_entry,params[:plucking])[0]
        translation = Translation.where(forum_id:entry[:id],language_id:language).pluck(:content)[0] unless language.nil?
        a_entry[content]=translation  unless translation.nil?
        full_list=Translation.where(forum_id:entry[:id]).pluck(:language_id)
        a_entry.push(!(full_list.size==language_list.size))
        if language_list.empty?
          a_entry.push(['nothing'])
        else
          this_list=[]
          language_list.each{ |thisone| this_list.push(thisone[:item]) unless full_list.include?(thisone[:id]) }
          a_entry.push(this_list.clone.to_json )
        end
      }
    else
      translation = Translation.where(forum_id:alist[:id],language_id:language).pluck(:content)[0]
      alist[:content]=translation  unless translation.nil?
    end
    params[:size] == 0   ?  alist[0]  : alist
  end
end

.get_translations(params) ⇒ Object

noinspection RubyLiteralArrayInspection



67
68
69
70
71
72
73
# File 'app/models/xforum/translation.rb', line 67

def self.get_translations(params)
  language_id = Language.get_me(params)
  topic_id = Topic.where(name:params[:topic]).pluck(:id)[0]
  #ForumAssist.named_array(Translation.where(topic_id:topic_id,language_id:language_id,state:['new','open']).pluck(:forum_id,:content,:suggestion),[:forum_id,:item,:suggestion])
  Translation.grab({topic_id:topic_id,language_id:language_id,state:['new','open']},[:forum_id,:content,:suggestion],{swap:{content: :item}})

end

.translate_list(alist, language, list_name) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/xforum/translation.rb', line 87

def self.translate_list(alist,language,list_name)
  alist.each.each {|entry|
    translation=Translation.find_by(forum_id:entry[:id],language_id:language)  unless language.nil?
    case list_name
      when 'category' , 'categories'
        entry.store(:item,Category.where(id:entry[:id]).pluck(:name)[0] )
        entry.store(:value,entry[:item])
      when 'topic'
        entry.store(:item,Topic.where(id:entry[:id]).pluck(:name)[0] )
        entry.store(:value,entry[:item])
      when 'language'
        translation ={content:entry[:value].concat(' - ').concat(entry[:local_name])}
        entry.store(:value,'wait')
      else
    end
    entry[:value]=translation[:content] unless translation.nil?
  }
  alist
end

.translate_to(list) ⇒ Object



23
24
25
26
27
28
29
# File 'app/models/xforum/translation.rb', line 23

def self.translate_to(list)
  list.each{|entry|
    translations=Translation.grab({forum_id:entry[:id]},[:language,:content],{})
    entry.store(:translations,translations)
  }
  list
end