Forum: Ruby on Rails Multilingual model content

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
18a4cfd669d998263f9824ed5efeab41?d=identicon&s=25 Michael Rigart (damick)
on 2009-05-13 08:56
Hi

I'm looking for some insight in a small problem I have. I allready
posted this in the Rails I18n forum, but didn't got any respond, so
maybe it was just the wrong forum.

I need multilingual input in my models. Lets say you have a Product
model. That product contains title, description and price. The price is
allways the same, but the title and description need to be inputted in
diffrent languages.

I have used the I18n framework build in Rails, so no external plugin and
I would like to keep it that way.

One idea I was playing with is the following model build:

Product
-------
id
price

ProductI18n
-----------
id
product_id
language -> I18n code like EN, BE, FR
title
description

But how do I link those 2 together, so that I can show the product
details in the current user language?

Is there a way to pass a variable trough the Product association like
this:

has_one :product_language, :class_name => :product_i18n, :conditions =>
"language = users_current_language_code"

I know I'm on the good track, but I know I'm missing something.

thank you for the insight
F625b891618be8ec32547a07b3192bb0?d=identicon&s=25 Francesc Esplugas (fesplugas)
on 2009-05-13 09:01
(Received via mailing list)
On Wed, May 13, 2009 at 8:56 AM, Michael Rigart
<rails-mailing-list@andreas-s.net> wrote:

> I need multilingual input in my models. Lets say you have a Product
> model. That product contains title, description and price. The price is
> allways the same, but the title and description need to be inputted in
> diffrent languages.

I wrote a plugin to solve the same problem you have.

   http://github.com/fesplugas/simplified_translation...

Hope that helps.
18a4cfd669d998263f9824ed5efeab41?d=identicon&s=25 Michael Rigart (damick)
on 2009-05-13 09:09
Francesc Esplugas wrote:
> On Wed, May 13, 2009 at 8:56 AM, Michael Rigart
> <rails-mailing-list@andreas-s.net> wrote:
>
>> I need multilingual input in my models. Lets say you have a Product
>> model. That product contains title, description and price. The price is
>> allways the same, but the title and description need to be inputted in
>> diffrent languages.
>
> I wrote a plugin to solve the same problem you have.
>
>    http://github.com/fesplugas/simplified_translation...
>
> Hope that helps.

Hi Francesc,

it looked good till I started reading further. I saw that you need to
define every language that you want to support in your attributes. The
thing I wanted to do is make sure that the list of supported languages
is dynamic.
F625b891618be8ec32547a07b3192bb0?d=identicon&s=25 Francesc Esplugas (fesplugas)
on 2009-05-13 09:25
(Received via mailing list)
On Wed, May 13, 2009 at 9:09 AM, Michael Rigart
<rails-mailing-list@andreas-s.net> wrote:

> it looked good till I started reading further. I saw that you need to
> define every language that you want to support in your attributes. The
> thing I wanted to do is make sure that the list of supported languages
> is dynamic.

In that case maybe the translate_column plugin by Sam Lown may work for
you.

    http://www.samlown.com/en/page/RailsTranslateColum...
110e527af05961700d9e39285d043b62?d=identicon&s=25 Gianluca Tessarolo (Guest)
on 2009-05-13 09:26
(Received via mailing list)
Hi Michael,

if you want to have dynamic language support the best choice may be:

http://github.com/janne/model_translations/

or (better)

http://github.com/joshmh/globalize2/

and if you want the versions for your translations:

http://github.com/joshmh/globalize2_versioning/

The only problem with these plugins is that you can't have the control
of the translation model (eg.: you cannot have an upload field on
translations model, it is difficult to apply constraints on translations
model, etc.), but if your goal is simply translating string fields these
plugins are great !
18a4cfd669d998263f9824ed5efeab41?d=identicon&s=25 Michael Rigart (damick)
on 2009-05-13 09:31
Hi,

I'm going to take a look at the RailsTranslateColumnsPlugin. Maybe I can
get some ideas from there.
F625b891618be8ec32547a07b3192bb0?d=identicon&s=25 Francesc Esplugas (fesplugas)
on 2009-05-13 09:39
(Received via mailing list)
Taking a look at the code, maintenance and test coverage in my opinion
model_translations
it's a better solution than translate_columns.

     http://github.com/janne/model_translations/tree/master

On Wed, May 13, 2009 at 9:31 AM, Michael Rigart
18a4cfd669d998263f9824ed5efeab41?d=identicon&s=25 Michael Rigart (damick)
on 2009-05-13 09:43
Francesc Esplugas wrote:
> Taking a look at the code, maintenance and test coverage in my opinion
> model_translations
> it's a better solution than translate_columns.
>
>      http://github.com/janne/model_translations/tree/master
>
> On Wed, May 13, 2009 at 9:31 AM, Michael Rigart

Hmm,

indeed, its looks tidy and support rails i18n. Thank for the input! :)
This topic is locked and can not be replied to.