Forum Moderators: phranque

Message Too Old, No Replies

multilingual website with mod_rewrite

         

gergoe

12:01 am on May 24, 2004 (gmt 0)

10+ Year Member



Any idea on how to implement a multilingual website? My first thought was to make it in the way that www.host.com/en/.* is the English, and www.host.com/fr/.* is the French version (and some more languages with their two letter codes). Sounds easy, but at the same time I have houndreds of "shortcuts" to some items on the website, also with letter codes, like www.host.com/eo or www.host.com/sne which leads to a specific page on the website (and which is not multilingual atm).

Using www.host.com/en/eo is difficult for the customer, and the brochures are printed with the "short" version (so it is not a choice anymore), and I'm, not sure that either the fr or the en or any of the languages codes are not exists in the list of these shourtcuts already. So it could be that I need www.host.com/fr for the French languaged website and I need www.host.com/fr for this shortcut thing also.

Is anyone had situation like this? Any idea or recommendation?

jdMorgan

12:47 am on May 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



www.hr.host.com
deutch.host.com
www.host.com/?lang=fr
www.host.com/l-en/eo

Any request without the language specified could default to the default site language, or to a page determined by the browser language settings based on HTTP_ACCEPT_LANGUAGE, or to a page showing language names and representative national flag icons to click on to set the language.

It is better to let the user choose than to make assumptions based on IP addresses, etc. For example, we have lots of people who speak only spanish in the U.S. Geo-IP redirection makes a lot of people mad, so let them choose manually if necessary.

Jim

gergoe

8:11 am on May 24, 2004 (gmt 0)

10+ Year Member



The l-en way sounds very good, but if the ppl who edits the pages on the site is not very aware of this and they might use the url for the links on the pages starting from the root /somedir/somepage, but it should be /lang/somedir/somepage, will it work if I check the referer, and if it does have the language code then I'll use that language again (otherwise the default one)? Sounds a bit difficult but might be the best?

pmkpmk

8:18 am on May 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A note from the end-user perspective: I hate it when I don't have a choice!

There's a couple of sites which geo-traget me and through me to a certain branch or language version regardless of what I do. Even assuming the good intention of providing a nice service to me (and keeping in mind the bad intention of hiding certain areas from me) there might be a lot of valid reasons why I may WANT to visit a branch other than the one intended for me. Maybe I just want to find out what the product is called in France, what it's price is in Cananda, what the referecne customers are in Japan, who the distributor is in Iceland. Or maybe I just want to check out the section my buddy from university manages who has moved to a different country after graduating.

Give the visitor the CHOICE to visit every language version you have! There's Spanish native speakers in Japan - they'd rather visit the Spanish language version instead of the Japanese version...

jdMorgan

1:16 pm on May 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> will it work if I check the referer [...]?

I would not rely on HTTP_REFERER for any critical function such as "remembering" the user's language. As we haved discussed in many times in "hotlinking" threads here, HTTP_REFERER is often blank, especially for visitors behind caching proxies or using "internet security" software.

If you don't want to put the language in the URL, a query string, or a sessionID, then I suppose you could use cookies.

Jim

gergoe

6:41 pm on May 26, 2004 (gmt 0)

10+ Year Member



I can't use cookies because the site is served by Apache and IIS separately, and IIS does not have any control on the http request (because of some (here) unimportant reasons), the only way to pass information to IIS is the query string. So either I'll use query string all over the website, which is taking the fact that the site is changed by many people without the proper knowledge of the html is not a good choice, the only way is left the mod_rewrite, with the language stored in the url somewhere. So I can take out the language from the url and put it into the query string. In the case when there's no language specified, I'll check the referer, if that has any language reference then I'll use that one, otherwise the default one. And on every page there will be a list with the available translations, so if the visitor are ended up on the wrong translation of the page, they will be able to switch at once.

Any suggestion, recommendation or idea?

jdMorgan

1:59 am on May 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm... Just a thought: Could you use mod_rewrite or a small script to take selected-language info from a cookie and add it to the URL as a query-string? Your front-end server could then pass this to your back-end as a query string, while the user would be able to select and keep his/her language settings as a cookie. I was looking at mod_usertrack, but that doesn't seem to be able to access the contents of the cookie, so some other mechanism (a script) might be needed. But I was thinking:

RewriteCond %{HTTP_COOKIE} ^lang=(.+)$
RewriteRule ^/(.+)\.html$ http://www.backend_server.com/handler.php?page=$1&lang=%1 [P]

Jim

gergoe

12:38 pm on May 27, 2004 (gmt 0)

10+ Year Member



And what about the requests when there's no cookie set?
If I use

RewriteCond %{HTTP_COOKIE} ^lang=(.+)$ [OR]
RewriteCond %{HTTP_COOKIE} !lang=
RewriteCond EN ^(.+)$
RewriteRule ^/(.+)\.html$ http://www.backend_server.com/handler.php?page=$1&lang=%1 [P]

...will do the trick, or do I need to handle the empty lang variable some other way (w/ an other rule for example)? I can't handle this on the back-end server because there are only xml files, w/o any form of server-sided script.

Actually my config is a bit complicated because of this reason, I have a bunch of RewriteRules which is passing the original request to the back-end server for a specific xml file (and which is being translated to html on the fly), it would not be nice to put RewriteCond(s) in the front of each RewriteRule, so likely the RewriteRule for this language thing will look like this:


RewriteRule ^/(.+)\.html$ /$1.html?lang=%1 [QSA]

jdMorgan

2:48 pm on May 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> do I need to handle the empty lang variable some other way (w/ an other rule for example)?

Yes, another rule would be needed, and you will need to use a script to set the cookie.


# If cookie exists and contains "lang=<something>, then rewrite with query string
RewriteCond %{HTTP_COOKIE} ^lang=(.+)$
RewriteRule ^/(.+)\.html$ http://www.backend_server.com/handler.php?page=$1&lang=%1 [P]
# Otherwise, redirect to default language, and tell script to set cookie
RewriteRule ^/(.+)\.html$ http://www.backend_server.com/handler.php?page=$1[b]&setcookie=true[/b]&lang=[b]EN[/b] [P]

I have no idea if this will actually work, so unless someone else replies on this subject, you'll need to set up and run a test. I assume you'll want to use your php script to set the cookie if it is missing, by appending a cookie header to the server response, so I have shown "setcookie=true" as a query string parameter to be used for this purpose. Also, somewhere on your site, you'll need to add the function to allow the user to change the language.

Jim