Making multi-language search pages ================================== Original idea instructions by Craig Small Some minor changes by Alex Barkov Introduction ------------ It is often required to allow for different languages which means different search.htm files depending on what language users have set in their browser. Please note that configuration issues given bellow are absolutely the same for both search.php and search.cgi front-ends. PHP specific issues ------------------- The only thing to be done in search.php is: a hack in config.inc to change the template file: $template_file= ereg_replace(".php", ".htm", basename(getenv("SCRIPT_FILENAME"))); $template_file = "/etc/somewhere" . $template_file; Further installation should be done in three steps. 1. Installing several templates ------------------------------- The general idea is to have one search.php or search.cgi file and then many search..htm files. You also have a search.htm file (usually a symlink to search.en.htm) for the default. If the name of the script is search.en.php (or search.en.cgi) then both CGI and PHP front-ends will be looking for /somewhere/etc/search.en.htm assuming that /somewhere/etc/ is /etc/ directory of mnoGoSearch installation. You would then populate /somewhere/etc/ with all the search.htm files so /somewhere/etc has: search.en.htm English template search.pl.htm Polish template search.ru.htm Russian template search.htm Symlink to English template 2. Installing front-ends ------------------------ Create a directory and put search.cgi or search.php there (along with the include files if you want, but I fiddle with the php include_path and put them elsewhere). Then setup the symlinks: search.cgi Original file search.en.cgi symlink search.pl.cgi symlink search.ru.cgi symlink Or in the case of PHP front-end: search.php Original file search.en.php symlink search.pl.php symlink search.ru.php symlink 3. Configuring Apache --------------------- You then need to make apache undestand what wierdness you are doing here. So you need to get negotiation happening and some magic with the indexes. I used .htaccess file but you could stick it in the apache config proper. AddLanguage en .en AddLanguage pl .pl AddLanguage ru .ru DirectoryIndex search search.cgi (or search.php) Options FollowSymlinks MultiViews How does it work? ----------------- So what happens, well it goes like this: 1) You type url http://myhost/mydir/search <- no slash at end !! 2) Your browser says "I like english (well language negotiation en) " 3) Apache finds search.en.cgi (DirectoryIndex gives search, MultiViews gives the en.cgi) 4) The SCRIPT_FILENAME which is used in both search.cgi and search.php is somepath/search.en.cgi (NOTE, most other variables will give the wrong result, either search or search.cgi) 5) Your hack in config.inc means you will use search.en.htm So what happens if the user wants, say, German? Well there is no search.de.cgi(search.de.php) so the first bit of DirectoryIndex fails, so it tries the second one, search.php OK, they get the page in English, but it's better than a 404. This does work, you may need some more apache fiddling to get negotiation to work because I am testing this on a server that already has it setup, so I may have missed something. Possible troubles ----------------- You may get some language negotiation problems caused by: 1) Dumb caches that don't follow standards 2) Dumb versions of browsers that don't follow standards 3) Dumb users fiddling with language settings and putting wierd stuff in. The apache team is working on some workarounds for most of these, if possible. For a reasonably heavily used website you can expect an email about it once a week or so.