trabajo-afectivo/app/models/translation.rb

26 lines
581 B
Ruby
Raw Normal View History

class Translation < ApplicationModel
2012-05-18 14:24:00 +00:00
before_create :set_initial
def self.translate(locale, string)
# translate string
records = Translation.where( :locale => locale, :source => string )
records.each {|record|
return record.target if record.source == string
}
# fallback lookup in en
records = Translation.where( :locale => 'en', :source => string )
records.each {|record|
return record.target if record.source == string
}
return string
end
2012-05-18 14:24:00 +00:00
private
def set_initial
self.target_initial = self.target
end
end