# My site in different languages

**URL:** <https://www.ruby-forum.com/t/my-site-in-different-languages/47948>\
**Category:** Rails\
**Created:** [November 15, 2005, 11:31am UTC](https://www.ruby-forum.com/t/my-site-in-different-languages/47948 "2005-11-15T11:31:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![brutyn\_nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@brutyn\_nick](https://www.ruby-forum.com/u/brutyn_nick)\
**Post date:** [November 15, 2005, 11:31am UTC](https://www.ruby-forum.com/t/my-site-in-different-languages/47948/1 "2005-11-15T11:31:49Z")

</div>

hey,

i want my site in different languages, such as english, dutch, french  
and  
german. How should i start? i have already a partial site in english.

I worked mostly with php. There my solution was working with templates,  
put them  
in folders like NL, ENG, FR, …, and based an a session variabele, load  
the  
right template.

something like this

$tpl = new HTML\_Template\_IT("./templates/nl/");  
$lang = “nl”;  
if ( isset($\_SESSION[“lang”]) )  
{  
$lang = $\_SESSION[“lang”];  
switch($lang)  
{  
case “eng”:  
{  
$tpl = new HTML\_Template\_IT("./templates/eng/");  
break;  
}  
case “nl”:  
default:  
{  
$tpl = new HTML\_Template\_IT("./templates/nl/");  
break;  
}  
}  
}else{  
$tpl = new HTML\_Template\_IT("./templates/nl/");  
}

But how to do this in ruby on rails? Cuz i dont know how to load an  
other  
template. it is all automatic ex.

u have a index.rhtml

def index  
some stuff  
end

the index.rhtml is loaded, but what if u have to load a template based  
on a  
paramater, like i used to do in php???

thanks for the help

---

<div class="post-metadata">

**Author:** ![brutyn\_nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@brutyn\_nick](https://www.ruby-forum.com/u/brutyn_nick)\
**Post date:** [November 15, 2005, 11:49am UTC](https://www.ruby-forum.com/t/my-site-in-different-languages/47948/2 "2005-11-15T11:49:58Z")

</div>

If you have the Agile book, you’ll want to look at p370. If not:

class YourController \< ApplicationController

layout :determine\_layout

…

private  
def determine\_layout  
# return the layout for whatever language you like  
end  
end

- james

---

<div class="post-metadata">

**Author:** ![brutyn\_nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@brutyn\_nick](https://www.ruby-forum.com/u/brutyn_nick)\
**Post date:** [November 15, 2005, 11:55am UTC](https://www.ruby-forum.com/t/my-site-in-different-languages/47948/3 "2005-11-15T11:55:59Z")

</div>

On Tuesday 15 Nov 2005 10:24, Brutyn N. wrote:

> i want my site in different languages, such as english, dutch, french and  
> german. How should i start? i have already a partial site in english.

You might want to check Multilingual Rails, which was here, but seems to  
have  
gone offline within in the last few days:

[http://www.tuxsoft.se/oss/rails/multilingual](http://www.tuxsoft.se/oss/rails/multilingual)

Google Cache works for the instructions, and if you want the source, I  
could  
email it to you, since I downloaded it last week.

Cheers,

~Dave

–

Dave S.  
Rent-A-Monkey Website Development  
Web: [http://www.rentamonkey.com/](http://www.rentamonkey.com/)

---

<div class="post-metadata">

**Author:** ![brutyn\_nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@brutyn\_nick](https://www.ruby-forum.com/u/brutyn_nick)\
**Post date:** [November 15, 2005, 1:53pm UTC](https://www.ruby-forum.com/t/my-site-in-different-languages/47948/4 "2005-11-15T13:53:04Z")

</div>

sure that would be great thanks

mail it to removed\_email\_address@domain.invalid

thanks 😉

---

<div class="post-metadata">

**Author:** ![brutyn\_nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@brutyn\_nick](https://www.ruby-forum.com/u/brutyn_nick)\
**Post date:** [November 15, 2005, 1:50pm UTC](https://www.ruby-forum.com/t/my-site-in-different-languages/47948/5 "2005-11-15T13:50:03Z")

</div>

thanks for this

i want to use the global rhtml (application.rhtml) also, then in the  
@content\_for\_layout, the specific language rhtml.

How should i do this??

if i do

def determine\_layout  
“clients/test”  
end

it must be in the clients folder, and i want also the application.rhtml,  
now he  
doesnt

thanks in advance

---

<div class="post-metadata">

**Author:** ![brutyn\_nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@brutyn\_nick](https://www.ruby-forum.com/u/brutyn_nick)\
**Post date:** [November 15, 2005, 2:30pm UTC](https://www.ruby-forum.com/t/my-site-in-different-languages/47948/6 "2005-11-15T14:30:28Z")

</div>

i forgot 1 think  
ex in clients controller i have index and list  
def index

end  
def list

end

for each of these pages i need the application.rhtml and the correct  
second  
rhtml in the specified language  
how must i create my folder structure ???  
something like this?  
clients  
eng  
index.rhtml  
list.rhtml  
nl  
index.rhtml  
list.rhtml  
and for ex the list.rhtml, i use a session variabele @session[:lang]

if @session[:lang] == “nl”  
…load the application.rhtml and clients\nl\list.rhtml  
end  
if @session[:lang] == “eng”  
…load the application.rhtml and clients\eng\list.rhtml  
end

does anyone know how to do this??Or got any better idea?

---

<div class="post-metadata">

**Author:** ![brutyn\_nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@brutyn\_nick](https://www.ruby-forum.com/u/brutyn_nick)\
**Post date:** [November 15, 2005, 7:09pm UTC](https://www.ruby-forum.com/t/my-site-in-different-languages/47948/7 "2005-11-15T19:09:41Z")

</div>

I’m solving this problem in a CMS I wrote, using routes. I can code  
the lang value straight into the url

map.connect ‘:lang/:accessname’, :controller =\> ‘page’, :action =\>  
‘show’

So “/en/index” shows the english version, and “/de/index” shows the  
german version. I prefer coding the lang field into the url instead  
of the session variable. A German website can then easily link to  
the german page.

Then I have translated images in “/images/en” and “/images/de”. I  
pull content from the database using the lang field and the accessname.

Hope this helps,  
Brett

---

<div class="post-metadata">

**Author:** ![brutyn\_nick](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e79b87/32.png) [@brutyn\_nick](https://www.ruby-forum.com/u/brutyn_nick)\
**Post date:** [November 15, 2005, 8:49pm UTC](https://www.ruby-forum.com/t/my-site-in-different-languages/47948/8 "2005-11-15T20:49:20Z")

</div>

There have been some big efforts lately to create a multilingual plugin  
for  
Rails that hopefully will go into the core eventually. A lot of people  
are  
asking for this to be core Rails.

You can download the beta plugin

svn://rashgash.co.il/rails-plugins/multilingual/trunk

Peter
