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 language.

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

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

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...

Example:

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

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

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
end

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

end

I18n.locale - application-level locale accessor.
I choose an approach (subdomain = locale):
- en.mysite.com - locale is 'en'
- ru.mysite.com - locale is 'ru' etc…

http://railscasts.com/episodes/221-subdomains-in-rails-3

On 16.09.2011, at 19:34, indi wrote:

hi,
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
point.

best regards,
indi

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 5, '12 at 2:20p
activeNov 5, '12 at 2:20p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Valery Kvon: 1 post

People

Translate

site design / logo © 2022 Grokbase