trabajo-afectivo/app/models/translation.rb

22 lines
487 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
record = Translation.where( :locale => locale, :source => string ).first
return record.target if record
# fallback lookup in en
record = Translation.where( :locale => 'en', :source => string ).first
return record.target if record
return string
end
2012-05-18 14:24:00 +00:00
private
def set_initial
self.target_initial = self.target
end
end