# Making my site multi-lingual

**URL:** <https://www.ruby-forum.com/t/making-my-site-multi-lingual/94708>\
**Category:** Rails\
**Created:** [May 11, 2006, 8:08pm UTC](https://www.ruby-forum.com/t/making-my-site-multi-lingual/94708 "2006-05-11T20:08:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 11, 2006, 8:08pm UTC](https://www.ruby-forum.com/t/making-my-site-multi-lingual/94708/1 "2006-05-11T20:08:57Z")

</div>

Hi,  
I’m wondering how I should go about making my website multi-lingual.  
Basically, there will be different content for the different  
languages, and that’s not really a problem… all I need to do is give  
each content entry in the database a language\_id. But the problem is  
with the non-content text, eg, “In order to access this area, you must  
be logged in”, “Created by”, “Last updated” etc. Surely rails has a  
way of making this simple. I just can’t find it. Anyone know how?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 11, 2006, 8:15pm UTC](https://www.ruby-forum.com/t/making-my-site-multi-lingual/94708/2 "2006-05-11T20:15:34Z")

</div>

removed\_email\_address@domain.invalid wrote:

> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

= Localization Plugin for Rails

This plugin provides a simple, gettext-like method to  
provide localizations.

== Features

- Any number of languages or locales
- Simple method to defines singluar/plural translations
- Can use lambdas to provide Ruby-code based dynamic translations
- Customizable for different instances of the application

== Usage

If the localization plugin is installed, it is used automatically.

You need to create a /lang dir in your RAILS\_ROOT.

The recommended way to use it is to create files that are named  
like the languages you define in them (but you can put everything in  
one big file too.)

For instance-customizable strings, add overrides in files you  
put in /lang/custom.

=== Simple example:

Create a file /lang/translations.rb:

Localization.define(‘de’) do |l|  
l.store ‘yes’, ‘Ja’  
l.store ‘no’, ‘Nein’  
end

Localization.define(‘fr’) do |l|  
l.store ‘yes’, ‘oui’  
l.store ‘no’, ‘non’  
end

In your controller or application.rb:

Localization.lang = ‘de’ # or ‘fr’

In your view:

\<%=\_ ‘yes’ %\>  
\<%=\_ ‘no’ %\>

Because the \_ method is simply an extension to Object, you  
can use it anywhere (models/controllers/views/libs).

=== Extended example:

Create a file /lang/default.rb with following contents:

Localization.define do |l|  
l.store ‘(time)’, lambda { |t| t.strftime(‘%I:%M%p’) }  
end

Create a file /lang/de\_DE.rb with following contents:

Localization.define(‘de\_DE’) do |l|  
l.store ‘%d entries’, [‘Ein Eintrag’, ‘%d Einträge’]  
l.store ‘(time)’, lambda { |t| t.strftime(‘%H:%M’) }  
end

In your controller or application.rb:

Localization.lang = ‘de\_DE’

In your view:

\<%=\_ ‘%d entries’, 1 %\> # singular variant is chosen  
\<%=\_ ‘%d entries’, 4 %\> # plural variant is chosen  
\<%=\_ ‘(time)’, Time.now %\> # call the block with a parameter

== Translation file guesstimation

You can generate a guesstimation of all strings needed to be  
translated in your views by first adding the \_(‘blah’) syntax  
everywhere and then calling:

puts Localization.generate\_l10n\_file

in the Rails console.

## Davis Zanetti Cabral Gtalk/Msn: daviscabral at gmail dot com

## Impact Media Estúdio de Criações [http://www.impactmedia.com.br/](http://www.impactmedia.com.br/)

Netiqueta  
Top x Bottom :: [http://tinyurl.com/pdnb2](http://tinyurl.com/pdnb2)  
Responder e-mails :: [http://tinyurl.com/rrv8d](http://tinyurl.com/rrv8d)

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [May 11, 2006, 8:28pm UTC](https://www.ruby-forum.com/t/making-my-site-multi-lingual/94708/3 "2006-05-11T20:28:20Z")

</div>

Hi,

On Thu, 11 May 2006 19:07:59 +0100  
removed\_email\_address@domain.invalid wrote:

> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

How about Ruby-GetText-Package?  
[http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html](http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html)
