Entry
What are some design techniques for multi-language sites?
How can I build a site that supports multiple languages?
May 18th, 2000 20:10
Nathan Wallace, Stephan Neander, Pavel Kaess, Dave Goodrich, Rob Hardowa
There are a few different ways to approach this complex problem:
- templates
- include files
- Apache with HTTP_ACCEPT_LANGUAGE
- gettext
Templates
~~~~~~~~~
The apache directive is a good idea although I haven't experimented with
it yet. I'm designing a site in English and Spanish, with plans for a
Portugese version.
I decided to go with templates instead of includes. I originally
started out with FastTemplates but after experimenting with it decided
on the template calss included with PHPLIB. I wanted to use PHPLIB for
sessions anyway so it was a natural.
I'm still in the early stages so i can't give you too much information.
As far as determining the language, you could use the apache directive,
or you could check what Languages are accepted by the client browser and
then respond accordingly. This is the option I'm tinkering with.
Basically here is how I grab the language.
1. Check the clients browser for what languages it accepts. If one is
on your list, feed them that document.
2. Keep track of the language using sessions.
3. always offer, on every page, the option to change to, or view the
document in an alternate language.
I'm using templates and mysql to cut down on the work and storage
requirements of having two of everything. Check out phpbuilder.com for
some good tutorials on how and why to use templates.
Include Files
~~~~~~~~~~~~~
First create a text file for each language containg entries such as:
$lang["msgErr_critical"] = 'Critical Error!';
$lang["msgErr_siteindex"] = 'Unable to create site index.';
$lang["msgErr_notexist"] = 'does not exist.';
This file would be duplicated for each language.
Then:
$gw_language = 'au'; // Language
// This could be set as a default or passed from a form.
$gw_dir_idx_base = '/home2/ace/idx/'; // Base IDX location
$gw_dir["lang"] = $gw_dir_idx_base.'lang/'; // Language files
// This is just to hold the directory where the language files belong.
// Include Language File
//////////////////////////////////////
include($gw_dir["lang"].$gw_language.".inc");
// This Includes the relevant file
Then just do something like the following:
$gw_error_msg = $lang["msgErr_notexist"].'<BR>P_IDX: '.$p_idx;
So the only thing that needs to change to switch languages is to change
the variable $gw_language
Apache with HTTP_ACCEPT_LANGUAGE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Curious ourselves we plan to use Apaches ability to select an index
paged based on the HTTP_ACCEPT_LANGUAGE arg. For instance the browser
ends 'en' we can use Apache to direct them to index.html.en which will
load an english php include file.
This of course leaves a defualt of english, haven't tried it yet, but we
believe it's the best solution we have thought up.
gettext
~~~~~~~
See:
http://www.faqts.com/knowledge-base/view.phtml/aid/2953/fid/422
http://www.faqts.com/knowledge-base/view.phtml/aid/2832/fid/422