Need some implementation ideas :-)

Hi,

I have good this cool challenge from my boss on developing a very simple
cms-like system to publish articles within. The caveat is that he wants
to have multi-lingual content.
At first I thought RoR would be perfect for the assignment but right now
I’m not so sure.

My first attempt involved creating a table for each model/languagde like
this:
articles_en
articles_dk
articles_de
etc

but then I will dynamically need to change the used table per request.
Seems like something that will slow down the app quite a bit.

Then I thought I could create the primary key in the table like a joined
key of the id field and language so I would have these ids:
1-en
1-de
2-en
2-dk
etc

But ActiveRecord doesn’t support multiple columns as primary key.

So right now I could some new idea or thought cause I’m sure RoR can do
everything - it’s only a matter on finding out how to do it :slight_smile:

Greetings,
Gitte W.

How about something like this…

class Article < ActiveRecord::Base
has_many :translations
end

class Translation < ActiveRecord::Base
belongs_to :article
validates_presence_of :language
validates_presence_of :body
validates_presence_of :title
end

tables…

articles
id INT(11) auto_increment, not null
other non-language specific fields, like publish time, etc…

translations
id INT(11) auto_increment, not null
article_id
language varchar(2)
title varchar(80)
body mediumtext

Then you could do something like

Articles.find_all_by_language(‘en’)
or
@article = Articles.find_by_id_and_language(params[:id],‘en’)

if necessary you could create a languages table and use a foreign key
instead of storing the two letter language code.

Gitte:
On Jan 4, 2006, at 4:57 AM, Gitte W. wrote:

So right now I could some new idea or thought cause I’m sure RoR
can do everything - it’s only a matter on finding out how to do it :slight_smile:

Have a table for languages as follows:

id
articleId
LanguageCode

in your articles model have :belongs_to language
and in your languages model have :has_many articles
Cheers,
Hasan D. [email protected]

Kevin O. wrote:

validates_presence_of :body
id INT(11) auto_increment, not null
article_id
language varchar(2)
title varchar(80)
body mediumtext

Then you could do something like

Articles.find_all_by_language(‘en’)
or
@article = Articles.find_by_id_and_language(params[:id],‘en’)

Hi Kevin,

Just wanted to say thanks for the idea - it works like a charm!

Greetings,
Gitte W.