Standard practice is to use a translation table using gem globalization. If you do not want to use gem globalization, you can do the following:
class City < ActiveRecord::Base AVAILABLE_LOCALES = [:en, :de, :fr] def name current_locale = I18n.locale if AVALIABLE_LOCALES.include? current_locale self.send("#{current_locale.to_s}_name") else #default language to use self.en_name end end end
It just shows the access code (name function), you can also write a mutator (name = function) so that you can set the value based on the current locale. I18n.locale will provide you with the current locale.
source share