I came across this question in "Rails Weenie" site and because there is no good answer for it there, here is my 2cents:
Yes it is. And exactly the way you described with php:
I suppose that you are familiar with Rails (creating projects, controllers,...etc)
We create a project called "myproject", we start WEBrick and we generate a controller named "test"
[root@mylinux]#rails myproject
[root@mylinux]#cd myproject
[root@mylinux myproject]#ruby script/server
[root@mylinux myproject]#ruby script/generate controller test
Create folders for your languages:
[root@mylinux myproject]#mkdir app/views/test/english
[root@mylinux myproject]#mkdir app/views/test/french
Create the english index.rhtml:
[root@mylinux myproject]#vi app/views/test/english/index.rhtml
Hi,
This is the english version.
Thanks.
Create the french version:
[root@mylinux myproject]#vi app/views/test/french/index.rhtml
Bonjour,
Ceci est la version francaise.
Merci.
Here is the solution (I create an action called "mustap" for testing):
[root@mylinux myproject]#vi app/controllers/test_controller.rb
class TestController < ApplicationController
def mustap
render :template => "test/" + @params["lang"] + "/index"
end
end
And now point your browser to these URLs:
http://localhost:3000/test/mustap/?lang=english
http://localhost:3000/test/mustap/?lang=french
Dadaaa!
UPDATE: This answer was selected as the best answer at "Rails Weenie"
I have an application that will have multi-language views spanish, english, etc. What i want to do is the next thing, on the views folder i want to create a folder named “spanish”, another one named “english”, etc. These folders will contain all the rhtml files of each language. But, the problem is...
When i want to acces the main page i will be redirected to the view of the language selected. For example, in PHP i will do something like this:
$language=”spanish”;
$url_to_show=”$language/index.php”;
On rails i have a controller with a function named index, and it shows the view “index.rhtml”... but i want to show the index.rhtml that is inside of the selected language folder
Is it possible?
Yes it is. And exactly the way you described with php:
I suppose that you are familiar with Rails (creating projects, controllers,...etc)
We create a project called "myproject", we start WEBrick and we generate a controller named "test"
[root@mylinux]#rails myproject
[root@mylinux]#cd myproject
[root@mylinux myproject]#ruby script/server
[root@mylinux myproject]#ruby script/generate controller test
Create folders for your languages:
[root@mylinux myproject]#mkdir app/views/test/english
[root@mylinux myproject]#mkdir app/views/test/french
Create the english index.rhtml:
[root@mylinux myproject]#vi app/views/test/english/index.rhtml
Hi,
This is the english version.
Thanks.
Create the french version:
[root@mylinux myproject]#vi app/views/test/french/index.rhtml
Bonjour,
Ceci est la version francaise.
Merci.
Here is the solution (I create an action called "mustap" for testing):
[root@mylinux myproject]#vi app/controllers/test_controller.rb
class TestController < ApplicationController
def mustap
render :template => "test/" + @params["lang"] + "/index"
end
end
And now point your browser to these URLs:
http://localhost:3000/test/mustap/?lang=english
http://localhost:3000/test/mustap/?lang=french
Dadaaa!
UPDATE: This answer was selected as the best answer at "Rails Weenie"
18 Sep 2007 22:04:22
This is far, far too much work for a Rails developer.
Use Globalize (http://www.globalize-rails.org), and just create templates like "index.de.rhtml", "index.en.rhtml", etc. The rest is automatic!