Link to home
Start Free TrialLog in
Avatar of dportabella
dportabella

asked on

multilanguage site in PHP

We currently have a web site written in (simple) PHP.

We would need to add the multilanguage feature,
that is, that the user can select in which language to view the website.

What would be the best way to implement this?
without changing too much our current PHP code.

Many thanks,
DAvid
Avatar of Joe Wu
Joe Wu
Flag of Australia image

No need to rewrite too much, but need to translate all your text into a foreign language, and store them say in a database table (each language has different table). Upon visitor visiting your site, default the site to english and let them choose language, if they chose another language, replace all the text you have translated (by retrieving foreign text from the database) and output them to the appropriate places to replace the english text.

It is a smart idea to have a table for english as well (your default language). Then when the user visits, retrieve the english values from the database. Make all your title, menutext, browser heading, etc.... as variables that are replaceable in terms of which language you have to retrieve from the database.

Hope this is an understandable explanation.
If the site isn' t that big, you could also use a language file,i.e. english.php, german.php, each one containing the text (in each language) you want in variables. In your code you just have to use the proper variables, depending in the user's language selection. I would prefer using XML to do that, but it might require a bit more programming work...

Bakos
Avatar of dportabella
dportabella

ASKER

Hello,

Thanks for the comments.
I guess that we are not the only ones with that need,
and we would prefer to use a standard approach.

We would prefer not using a sql database.
Defining variables (in separate php files or xml files) would be nice, but still a little cumbersome.

We would really like to have everything (the php code + the text in the different languages) all together in the same php files.

Do you know of full simple concrete implementation examples that we can look at?


Many thanks,
DAvid
ASKER CERTIFIED SOLUTION
Avatar of x_bakos
x_bakos
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial