Forum: Ruby on Rails multiple language application

9c9141dd25ef39d9bfde1072867b07fc?d=identicon&s=25 indi (Guest)
on 2011-09-17 09:12
(Received via mailing list)
I've been asked to design a multiple language application for an
architectural firm and I need advice with which is the best approach
to it with Rails.
Basically all the tables have some common fields that doesn't need to
be translated and some others that need translation.
At first it seems the application will be quite changing since not all
the targets are clearly defined so, ease of change will make a good

best regards,
8febdd9affa395c8a53796d1150ffb70?d=identicon&s=25 Valery Kvon (Guest)
on 2012-11-05 15:22
(Received via mailing list)
Just right now I'm solving definitely this kind of task.

I choose an approach where each content having to be translated, is
String or Text.
Then I created two STI+polymorphic tables (models): MetaText and
MetaString. Each of them has columns "value" and "locale" to specify

class MetaString < ActiveRecord::Base
  attr_accessible :value, :locale
  belongs_to :resource, :polymorphic => true

class MetaText < ActiveRecord::Base
  attr_accessible :value, :locale
  belongs_to :resource, :polymorphic => true

For each model I've created STI models for whatever string/text content
to be translated. STI is needed to specify model behavior, such as
validation or etc...


class ArticleTitle < MetaString
   validates_lenght_of :value, :maximum => 200

class ArticleContent < MetaText
   validates_lenght_of :value, :minimum => 200

class Article < ActiveRecord::Base
  has_many :titles, :class_name => "ArticleTitle", :as => :resource,
:dependent => :delete_all
  has_many :contents, :class_name => "ArticleTitle", :as => :resource,
:dependent => :delete_all

  def title(locale=nil)
    items = titles.to_a
    items.find {|i| i.locale == locale || I18n.locale} || items.first

  def content(locale=nil)
    items = contents.to_a
    items.find {|i| i.locale == locale || I18n.locale} || items.first


I18n.locale - application-level locale accessor.
I choose an approach (subdomain = locale):
- - locale is 'en'
- - locale is 'ru' etc
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.