By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,316 Members | 2,132 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,316 IT Pros & Developers. It's quick & easy.

multilanguage website

P: n/a
I'm trying to make a multilanguage website. When the user enters the site, I want to detect the language and automatically make a redirection. How can I do this? And how should I organize my data base so the user can switch languages easily?

Thanks.
Jul 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Mariano López wrote:
I'm trying to make a multilanguage website. When the user enters the
site, I want to detect the language and automatically make a
redirection. How can I do this? And how should I organize my data
base so the user can switch languages easily?

Thanks.


Detecting language... not easy at all. You could try to do a reverse lookup
on the IP address and grab a country from that, but that may be slow.
Personally, I would display either a map of the world with regions
clickable, or (my personal preference) flags. Then just keep that in the
query string (e.g. blah.php?lang=en) or in a session variable (perhaps less
preferable if you have a ton of users). When querying your db for content,
just tack on an extra row (of type enum) for the language.

My $.02
// Ian Fette
// Proponent comp.lang.php
Jul 16 '05 #2

P: n/a
Agelmar wrote:
Mariano López wrote:
I'm trying to make a multilanguage website. When the user enters the
site, I want to detect the language and automatically make a
redirection. How can I do this? And how should I organize my data
base so the user can switch languages easily?

Thanks.


Detecting language... not easy at all. You could try to do a reverse
lookup on the IP address and grab a country from that, but that may
be slow. Personally, I would display either a map of the world with
regions clickable, or (my personal preference) flags. Then just keep
that in the query string (e.g. blah.php?lang=en) or in a session
variable (perhaps less preferable if you have a ton of users). When
querying your db for content, just tack on an extra row (of type
enum) for the language.

My $.02
// Ian Fette
// Proponent comp.lang.php


Hi. I've found an easy solution to language detection by using Javascript (it checks the browser's language configuration).

Now I'm thinking if I'm going to use a session variable (I didn't want to mess with it, but maybe I do ;-)))

Thanks.
Jul 16 '05 #3

P: n/a
sam
You can use the ip-to-country database.

---------------- CUT HER ------------------------------
$user_ip = $_SERVER['REMOTE_ADDR'];
$country_code_type = "name"; // can be "name", "code2" or "code3"

$h =
fopen("http://ip-to-country.directi.com/country/$country_code_type/$user_ip"
,'r');
$user_country = fgets($h,4096);
fclose($h);
---------------- END -----------------------------------

You can download the database from http://ip-to-country.directi.com and
you access it locally if you want.

For more details: http://ip-to-country.directi.com

Hope this helps.
"Mariano López" <vi******************@infovia.com.ar> wrote in message
news:be************@ID-156496.news.uni-berlin.de...
I'm trying to make a multilanguage website. When the user enters the site, I
want to detect the language and automatically make a redirection. How can I
do this? And how should I organize my data base so the user can switch
languages easily?

Thanks.
Jul 16 '05 #4

P: n/a
You might want to look over some HTTP request headers:

$_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ]

Or look over get_browser(), there is one of the values that identifies
the browser's language if I remember well, but it should be the same value.

Agelmar wrote:
Mariano López wrote:
I'm trying to make a multilanguage website. When the user enters the
site, I want to detect the language and automatically make a
redirection. How can I do this? And how should I organize my data
base so the user can switch languages easily?

Thanks.

Detecting language... not easy at all. You could try to do a reverse lookup
on the IP address and grab a country from that, but that may be slow.
Personally, I would display either a map of the world with regions
clickable, or (my personal preference) flags. Then just keep that in the
query string (e.g. blah.php?lang=en) or in a session variable (perhaps less
preferable if you have a ton of users). When querying your db for content,
just tack on an extra row (of type enum) for the language.

My $.02
// Ian Fette
// Proponent comp.lang.php


Jul 16 '05 #5

P: n/a
Mariano López wrote on Saturday 12 July 2003 12:10:
I'm trying to make a multilanguage website. When the user enters the site,
I want to detect the language and automatically make a redirection. How
can I do this? And how should I organize my data base so the user can
switch languages easily?


If you run Apache or any capable web server, then you can leave the client
language detection and preference to it and let it serve appropriate
file(s). See more in Apache docs.

Then, based on which file is served, set language preferences in your PHP
app and allow change back and forth. As far as separating data, make sure
all language-specific content is defined separately from your main
application, and include() language-specific include files (containing
appropriate variables and language-specific content) in each script that
outputs or otherwise processes said content.

Depending on complexity of your application, and variety of languages this
could be anywhere from very simple to somewhat challenging.

--
Business Web Solutions
ActiveLink, LLC
www.active-link.com/intranet/
Jul 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.