I have an object called human and that object has a field called job. I want users to be able to add their own jobs (which will obviously be added in their own language) but I want to have any job that is a default in the database to be translated when someone does a Human.job, can rails translate the default if it is in the view but not if it is in the model as I have some sql logic that tests how many humans have the job of coder.
#Human
class Human < ActiveRecord::Base
validates_presence_of :job, :name
def job
if is_view?
key = job.gsub(/ /,'_')
translation = I18n.translate("jobs.#{key.downcase}")
if translation.include?('translation missing:')
job
else
translation
end
else
job
end
end
end
#en.yml
en:
jobs:
coder: 'coder'
#en-Accountants.yml
en-Accountants:
jobs:
coder: 'slave'
#fr.yml
fr:
jobs:
coder: 'le coder'
eg:
A human 'Bob' with a job of 'Coder' should be 'slave' to accountants and 'le coder' to those using the app in french but I should be able to still do a find for every coder.