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