Hi
I faced the same dilemma in past projects. For projects that only
have two languages and will never have more, I simply have the fields
end with _fr on _en (i.e. title_fr and title_en) for the fields that
need to have to versions of the same content. I also create virtual
attributes that use a global setting (I use Globalite -
http://agilewebdevelopment.com/plugins/globalite) to figure out the
current language and return the appropriate attribute. This way, in
your public views, you don't have to do an if statement on the current
language, you simply access the virtual attribute (page.title instead
of page.title_fr). See code example below. And by using Globalite, you
have one single view to maintain, not one per language.
If you are planning to support more than 2 languages, I suggest that
you add a has_many association to a sub-model that will contain the
translated data. You could also take a look at the Globalize plug-in
(
http://agilewebdevelopment.com/plugins/globalize). Never had to deal
with more than 2 languages, but will in a few weeks.
module ActiveRecordExtensions
# Bilingual virtual attributes.
# Defines vitual attribute getters for the given attribute names
def bilingual_attributes(*names)
names.each do |name|
define_method "#{name}" do
read_attribute(name.to_s
+"_#{Globalite.current_language.to_s}")
end
end
end
end
# Add our own ActiveRecord extensions
class ActiveRecord::Base
extend ActiveRecordExtensions
end
class Page < ActiveRecord::Base
bilingual_attributes :body, :title, :title_prefix
end
There you go, hoping it helps you
Hugo
On Jul 21, 10:22 am, tadatoshi <
tadatoshi.mailingl...@gmail.com>
wrote: