Recommendation for separating English and French sites

0 views
Skip to first unread message

tadatoshi

unread,
Jul 21, 2008, 10:22:48 AM7/21/08
to Montreal on Rails
Hi,

Is there any recommended way to separate English site and French
site?
Especially, when the content is added by the user separately in
English and French for the same one topic, how do you recommend to
structure models and store in database?
I want to keep the search for the content simple also.

I have been doing it in my own way. But I think it's time to follow
the best practices if there is any.

Thank you.

Frahugo

unread,
Jul 23, 2008, 3:42:47 PM7/23/08
to Montreal on Rails
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:

tadatoshi

unread,
Jul 23, 2008, 11:36:41 PM7/23/08
to Montreal on Rails
Thank you, Hugo.

I appreciate your advices very much.

Sincerely,
Tadatoshi


On Jul 23, 3:42 pm, Frahugo <hugo.frapp...@gmail.com> wrote:
> 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

tadatoshi

unread,
Jul 29, 2008, 9:19:18 PM7/29/08
to Montreal on Rails
Hi, Hugo,

I have tried out Globalite and also looked at the code for its
example.
But I have a question.
How do you deal with user session?
When one user session changes Globalite.current_language (, which is a
class variable) to :en, for example, all the other user sessions see
the English content even when they are intending to see French
content.

Thank you.
Tadatoshi


On Jul 23, 11:36 pm, tadatoshi <tadatoshi.mailingl...@gmail.com>
wrote:

Matt Aimonetti

unread,
Jul 30, 2008, 3:15:44 AM7/30/08
to montreal...@googlegroups.com
Hi Tadashi,

 A session is specific to 1 user so that won't be a problem. Internally, I made Globalite store the locale in a class variable (kind of bad design) because Rails is not thread safe. However because we are using an around filter, the variable gets set when the controller gets initialized and gets released/reset at the end of the action.

Also I would recommend to use localized routes (better SEO) which I didn't do in the example app.

-Matt

tadatoshi

unread,
Jul 30, 2008, 7:48:27 AM7/30/08
to Montreal on Rails
Hi, Matt,

Thank you for your reply.

I apologize if I was not clear.
But yes, a session is specific to one user but the class variable set
by one user is not specific to one user and it's shared with other
users.
At least, that's what I observed. (I'm using Mongrel, by the way.)

But this discussion is getting longer than I expected.
So I will send you an e-mail directly to you with more questions.

Sincerely,
Tadatoshi


On Jul 30, 3:15 am, "Matt Aimonetti" <mattaimone...@gmail.com> wrote:
> Hi Tadashi,
>
> A session is specific to 1 user so that won't be a problem. Internally, I
> made Globalite store the locale in a class variable (kind of bad design)
> because Rails is not thread safe. However because we are using an around
> filter, the variable gets set when the controller gets initialized and gets
> released/reset at the end of the action.
>
> Also I would recommend to use localized routes (better SEO) which I didn't
> do in the example app.
>
> -Matt
>
> On Wed, Jul 30, 2008 at 3:19 AM, tadatoshi
> <tadatoshi.mailingl...@gmail.com>wrote:
Reply all
Reply to author
Forward
0 new messages