My site in different languages


#1

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


#2

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

#3

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

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/


#4

sure that would be great thanks

mail it to removed_email_address@domain.invalid

thanks :wink:


#5

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


#6

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?


#7

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


#8

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