Search pages with multi-lingual interface

The original instructions in this article were made by Craig Small . Some later changes were done by Alexander Barkov .

In case of a multi-lingual search engine it is convenient to display search form and search results using the language according to the user browser preferences. This article describes how to configure a multi-lingual interface for the mnoGoSearch + Apache combination.

Installing a multi-lingual interface

The general idea of this method uses the fact that search.cgi opens a template having the same name with the CGI script. For example, if the name of the CGI script is search.en.cgi, then it opens the template file /usr/local/mnogosearch/etc/search.en.htm (assuming that mnoGoSearch /etc directory is /usr/locale/mnogosearch/etc/). Configuring a multi-lingual interface consists of three simple steps.

  1. Installing multiple templates

    You need to create multiple search templates (one template for every language you want to support) with file names in the form search.language.htm, where language is a two-letter language abbreviation, for example: en, pl, ru.

    You may also want to have the file search.htm (usually a sym-link to search.en.htm) as the default file.

    At the end of this step you will have these files in mnoGoSearch /etc directory:

    search.en.htm English template Polish template Russian template
    search.htm Symlink to the English template

  2. Installing front-ends

    Put search.cgi into your Web server CGI directory and setup the symlinks:

    search.cgi The original file
    search.en.cgi symlink symlink symlink

  3. Configuring Apache

    You also need to make your Apache understand the trick you are doing here to have content negotiation happen, as well as some magic with the indexes. It can be done either in httpd.conf, or in the .htaccess file in the directory you put search.cgi in.
AddLanguage en .en
    AddLanguage pl .pl
    AddLanguage ru .ru
    DirectoryIndex search search.cgi
    Options FollowSymlinks MultiViews

How it works

  1. You open your browser and type the 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, and MultiViews gives en.cgi)

  4. Apache sets the environment variable SCRIPT_FILENAME to mydir/search.en.cgi and executes search.en.cgi.

  5. search.en.cgi starts and detects the template name using SCRIPT_FILENAME.

So what happens if the user wants, say, German? Note, there is no! The first bit of DirectoryIndex (i.e. search) fails, so Apache tries the second one, search.cgi and executes it. search.cgi starts and opens the template file search.htm, which is a symlink to search.en.htm. So you'll get the page in English, which is better than a 404 Not Found.

Possible troubles

Rarely you may get some language negotiation problems caused by: