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
65
66
67
68
69
70
71
72
73
|
# File 'lib/ixtlan/models/phrase.rb', line 40
def self.all(args = {})
phrases = ::DataMapper::Collection.new(::DataMapper::Query.new(self.repository, Ixtlan::Models::Phrase), [])
map = {}
locale = args[:locale] || LOCALE.default
TEXT.not_approved(args.dup).each do |text|
phrase = Phrase.new(:code => text.code, :text => text.text, :current_text => text.text, :locale => locale, :updated_at => text.updated_at, :updated_by => text.updated_by)
map[phrase.code] = phrase
end
TEXT.latest_approved(args.dup).each do |text|
if (phrase = map[text.code])
phrase.current_text = text.text
else
phrase = Phrase.new(:code => text.code, :text => text.text, :current_text => text.text, :locale => locale, :updated_at => text.updated_at, :updated_by => text.updated_by)
map[phrase.code] = phrase
end
end
case locale.code.size
when 2
params = args.dup
params[:locale] = LOCALE.default
Translation.map_for(params).each do |code, trans|
ph = map[code]
if(ph.nil?)
map[code] = Phrase.new(:code => code, :text => trans.text, :current_text => trans.text, :locale => locale, :updated_at => trans.approved_at, :updated_by => trans.approved_by, :default_translation => trans)
else
ph.default_translation = trans
end
end
when 5
raise "not implemented yet"
end
map.values.each { |ph| phrases << ph}
phrases
end
|