Selecting a Language in a Site

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Selecting a Language in a Site

Post by Maluendaster »

Does anyone knows where i can get a tutorial to learn how to create a multilingual site?

Thank you.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Have a look at gettext php extension there are tutorials about that and at least one on, the excellent, sitepoint. There are many other issues concerning multi language sites. I believe PEAR and the Zend Framework have a bunch of tools for managing other issues such as those to do with dates and times. UTF-8 support for all unicode characters is quite useful but a bit of a hassle in PHP.
If you are only serving static pages Apache's content negotiation may be of interest, you can probably recreate it's behaviour in pretty easily PHP.

Final note: we tend to be more helpful on specific issues.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

language files

Post by yacahuma »

i just read a little on gettext and I jave no idea of what it does. I know I have done site with spanish and english in a very simple manner.

I created a directory called languages. There I have en.php and spa.php

inside you will see something like

Code: Select all

en.php
$dog_la = 'dog';
$cat_la = 'cat';

spa.php
$cat_la = 'gato';
$dog_la = 'perro';

you get the idea.
In every page you will use the variable defined on the language files instead of the word
Use a session to keep track of which language the user wants.

Code: Select all

include 'languages/' . $_SESSION['language'] . '.php';
Simple but effective.
matteoraggi
Forum Newbie
Posts: 2
Joined: Sun Feb 03, 2008 3:42 pm
Location: Italy
Contact:

Re: Selecting a Language in a Site

Post by matteoraggi »

what about if someone want to translate not only simple text but categories and subcategories, for example here:
http://www.hotel-supplies.biz
I desire to translate it also in italian language: http://www.forniture-alberghiere.net and german: http://hotelbedarf.biz
which is the best way to do this work for me?
I just not have any multi-language script in this moment installed..
Post Reply