# Multilingual Plugin

**URL:** <https://www.ruby-forum.com/t/multilingual-plugin/48578>\
**Category:** Rails\
**Created:** [November 22, 2005, 1:12pm UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578 "2005-11-22T13:12:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmharvey.9956003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jmharvey.9956003](https://www.ruby-forum.com/u/jmharvey.9956003)\
**Post date:** [November 22, 2005, 1:12pm UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578/1 "2005-11-22T13:12:40Z")

</div>

I’m releasing my big multilingual plugin. It was originally based on  
Per Wigren’s MLR code, but it’s been redesigned and written from  
scratch, under the MIT License. This is the first public release, so  
although it passes all the unit tests, I expect there to be some  
glitches.

Here’s what it does:

```
* Simple to use.
* Translates both db content and view text.
* Supports automatic selection of an alternate, localized template

```

for each view.  
\* Built-in localization and translation of strftime, numbers, and  
currency formats.  
\* Supports pluralization.  
\* All data is stored in three, automatically migrated, database  
tables.

Installation

1. script/plugin install  
[https://OpenSVN.csie.org/multi\_lingual\_rails/multilingual/trunk](https://OpenSVN.csie.org/multi_lingual_rails/multilingual/trunk)
2. script/generate multilingual (generates a new migration)
3. rake migrate

See the wiki at:  
[https://opensvn.csie.org/traccgi/multi\_lingual\_rails/trac.cgi/wiki](https://opensvn.csie.org/traccgi/multi_lingual_rails/trac.cgi/wiki)

RDoc will be available as soon as I find somewhere to upload it.

---

<div class="post-metadata">

**Author:** ![jmharvey.9956003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jmharvey.9956003](https://www.ruby-forum.com/u/jmharvey.9956003)\
**Post date:** [November 22, 2005, 2:05pm UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578/2 "2005-11-22T14:05:05Z")

</div>

Joshua Harvey wrote:

> ```
> * Supports automatic selection of an alternate, localized template
> 
> ```
> 
> 1. script/generate multilingual (generates a new migration)
> 2. rake migrate
> 
> See the wiki at:  
> [https://opensvn.csie.org/traccgi/multi\_lingual\_rails/trac.cgi/wiki](https://opensvn.csie.org/traccgi/multi_lingual_rails/trac.cgi/wiki)

Congratulations,

boy, this is good news. The feature set looks “really” nice. Can’t wait  
to  
try it and see it mature.

Sascha E.

---

<div class="post-metadata">

**Author:** ![jmharvey.9956003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jmharvey.9956003](https://www.ruby-forum.com/u/jmharvey.9956003)\
**Post date:** [November 22, 2005, 2:09pm UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578/3 "2005-11-22T14:09:06Z")

</div>

Thanks merci grazie danke! 🙂

Il giorno 22/nov/05, alle ore 13:10, Joshua Harvey ha scritto:

---

<div class="post-metadata">

**Author:** ![jmharvey.9956003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jmharvey.9956003](https://www.ruby-forum.com/u/jmharvey.9956003)\
**Post date:** [November 22, 2005, 3:41pm UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578/4 "2005-11-22T15:41:41Z")

</div>

Hi

> Installation
> 
> 1. script/plugin install  
> [https://OpenSVN.csie.org/multi\_lingual\_rails/multilingual/trunk](https://OpenSVN.csie.org/multi_lingual_rails/multilingual/trunk)
> 2. script/generate multilingual (generates a new migration)
> 3. rake migrate

After the first step, I’m getting the following message when I try to  
start  
the server:

aroedl@hydra ~/user/qasar11 $ ./script/server  
=\> Booting WEBrick…  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active\_support/dependencies.rb:200:in  
`const\_missing’: uninitialized constant CoreExtensions (NameError)

from  
./script/…/config/…/vendor/plugins/multilingual/lib/multilingual/localization/core\_ext\_hooks.rb:4  
from  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in  
`require’

from  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active\_support/dependencies.rb:214:in  
`require’

from /usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/initializer.rb:315:in  
`load\_plugin’

from /usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/initializer.rb:315:in  
`load\_plugin’

from /usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/initializer.rb:306:in  
`load\_plugin’

from  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active\_support/core\_ext/kernel.rb:27:in  
`silence\_warnings’

from /usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/initializer.rb:306:in  
`load\_plugin’  
… 10 levels…

from /usr/lib/ruby/gems/1.8/gems/rails-0.14.3/lib/commands/server.rb:28  
from  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in  
`require’

from  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.2.3/lib/active\_support/dependencies.rb:214:in  
`require’  
from ./script/server:3

As soon as I remove the multilingual from the plugins directory,  
everything is  
fine. I can’t actually get a clue from the error message… ☹

Ruby 1.8.3  
Rails 0.14.3  
Active Record 1.13.0  
Action Pack 1.11.0  
Action Mailer 1.1.3  
Active Support 1.2.3  
AWeb Service 0.9.3

Andreas

---

<div class="post-metadata">

**Author:** ![jmharvey.9956003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jmharvey.9956003](https://www.ruby-forum.com/u/jmharvey.9956003)\
**Post date:** [November 22, 2005, 6:26pm UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578/5 "2005-11-22T18:26:52Z")

</div>

Hi Joshua,

The feature list looks great!

I haven’t seen the String division operator used before. The pickaxe  
book  
has a reference (  
[Programming Ruby: The Pragmatic Programmer's Guide](http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_string.html#String._pc))  
to the % operator for String formatting but I can’t find any references  
to  
/. How does this work?

Thanks

---

<div class="post-metadata">

**Author:** ![jmharvey.9956003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jmharvey.9956003](https://www.ruby-forum.com/u/jmharvey.9956003)\
**Post date:** [November 22, 2005, 6:55pm UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578/6 "2005-11-22T18:55:05Z")

</div>

±le 22/11/2005 14:10 +0200, Joshua Harvey a dit :  
| 2. script/generate multilingual (generates a new migration)

That phase is a bit too MySQL centric, you can’t do that kind of insert  
with  
other databases.

---

<div class="post-metadata">

**Author:** ![jmharvey.9956003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jmharvey.9956003](https://www.ruby-forum.com/u/jmharvey.9956003)\
**Post date:** [November 23, 2005, 12:09am UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578/7 "2005-11-23T00:09:18Z")

</div>

Hi Joshua,

Joshua Harvey wrote:

> I’m releasing my big multilingual plugin.  
> …  
> \* All data is stored in three, automatically migrated, database tables.

You made a great work.  
If I can make a small reserve, I’m not convinced by the db design  
retained. Storing (table\_name, field\_name, value) for each translatable  
field seems not to be the best way, though for sure it’s a good way to  
‘multilinguize’ a legacy app.  
The better way would be to change

TABLE  
id  
field1  
field2  
translatable\_field1  
translatable\_field2

into

TABLE TABLE\_translations  
id \<------\ id  
field — main\_model\_id (belongs\_to TABLE)  
lang  
translatable\_field1  
translatable\_field2

It’s cleaner imho.  
I think such migration would be possible with a script that would  
analyze models.

## Is there a reason why you didn’t retain such design ?

Jean-Christophe M.

---

<div class="post-metadata">

**Author:** ![jmharvey.9956003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jmharvey.9956003](https://www.ruby-forum.com/u/jmharvey.9956003)\
**Post date:** [November 23, 2005, 1:06am UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578/8 "2005-11-23T01:06:16Z")

</div>

Nice one, this is a great start. I am very much looking forward to  
trying this out in the next couple of weeks.

Database thoughts:

It’s late and I’m tired but why not something like:

LANGUAGES  
id  
country\_code  
currency\_things  
time\_things

PHRASES  
id  
original\_phrase\_to\_be\_translated

TRANSLATIONS  
id  
language\_id  
phrase\_id  
translation

Then you can do things like

PHRASEGROUPS  
id  
phrase\_id

for nice translatino admin such as 'these are all the phrases for  
mymodel.rb/.rhtml myothermodel.rb/.rhtml

---

<div class="post-metadata">

**Author:** ![jmharvey.9956003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jmharvey.9956003](https://www.ruby-forum.com/u/jmharvey.9956003)\
**Post date:** [November 22, 2005, 2:33pm UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578/9 "2005-11-22T14:33:15Z")

</div>

Hi, Joshua,

really great news. Thanks a million!

Regarding the RDoc: What do you need for that? Just some upload space? I  
think that would be no problem, just give the list a note (or write  
directly to removed\_email\_address@domain.invalid) what your requirements are…

regards  
Jan P.

---

<div class="post-metadata">

**Author:** ![jmharvey.9956003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jmharvey.9956003](https://www.ruby-forum.com/u/jmharvey.9956003)\
**Post date:** [November 23, 2005, 12:37am UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578/10 "2005-11-23T00:37:28Z")

</div>

Jean-Christophe M. wrote:

> field seems not to be the best way, though for sure it’s a good way to  
> into  
> analyze models.
> 
> Is there a reason why you didn’t retain such design ?

I am inclined to agree with that. Can you explain why you did that? I  
mean,  
what was you motivation to do it that way? I would tend to just use a  
field  
extension:

TABLE  
id  
field  
field\_de\_DE  
field\_en\_EN  
field\_fr\_FR

The problem is that this would probably make the table definitions  
harder  
to maintain, but, it would certainly be more performant. The logic would  
be  
easier. It would also be easier to index (create indices).

Abstracting out this logic so early seems a little like premature  
optimization.

Please enlighten us.

Sascha E.

---

<div class="post-metadata">

**Author:** ![jmharvey.9956003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dbc845/32.png) [@jmharvey.9956003](https://www.ruby-forum.com/u/jmharvey.9956003)\
**Post date:** [November 22, 2005, 8:03pm UTC](https://www.ruby-forum.com/t/multilingual-plugin/48578/11 "2005-11-22T20:03:34Z")

</div>

congrats for great work. thats fabulous. is there any plans for making  
the  
translations file cached? I mean without needing db access?
