7.2. Making multi-language search pages

Original idea instructions by Craig Small . Some minor changes by Alex Barkov .

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.

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.[language].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 DataparkSearch 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

    Then you need to make apache understand what weirdness 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

7.2.1. How does it work?

  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.

7.2.2. Possible troubles

You may get some language negotiation problems caused by:

The apache team is working on some workarounds for most of these, if possible. For a reasonably heavily used web site you can expect an email about it once a week or so.