MultilingualSupport - compuphase/sphider-pdo GitHub Wiki
Most sites use only a single language. Although the original Sphider supports multiple languages, it considers that a site will choose only one. This derivative, Sphider-PDO, has improved support for multilingual sites, although it is still limited.
Starting with version 1.3.6, Sphider now also stores the language that is set in a web page into the database. You can set a language in the "<HTML>
" tag. For example, when the page is written in German, you can start the HTML code with "<html lang='de'>
".
When you have an existing Sphider database of version 1.3.5 or earlier, you must rebuild the database. The easiest way to do this is to erase the database and then run "install.php" again. After that, create the site definitions and index them (full index).
The default language for a search is set in the file config.php. As explained in the page on integrating search on your site, you can override the language with a hidden field on your search form. So, if a user has chosen to view your site in German (explicitly or based on the language of his/her browser), the matching search form can contain the following code:
<input type="hidden" name="lang" value="de">
The language code from the above hidden field, is passed onto the search results template as a global variable, called $language
.
The lay-out of the search page is defined in a template. Despite the template files having the "html" extension, they are pulled in from PHP code, and therefore, they can contain PHP code sections. The template can therefore adapt specific texts to the active language by testing the $language
variable.
Part of the template is the "header.html" file, which typically contains the largest section of the code. As an alternative to creating a single "header.html" file (and enclosing relevant snippets in PHP sections that output different strings depending on the value of $language
), you can create a language-specific file for each supported language. The language code is appended to the base filename. For French, the header filename would be "header_fr.html". This is also supported for the "footer.html" file. The other files in the template exist only as a universal file (without language suffix).
In the "search result" template, the language of each URL/page is passed in the $qry_results[n]['lang']
(where n
is an index). The templates provided with Sphider-PDO do not take advantage of this field, but if you have a multilingual site, you can use this field to show the language of the page.
When a language is set for an URL/page and this language is not the same as the user language (as passed through the form), the weight of the match is decreased. This way, if a page exists in multiple languages, the one in the user's language comes on top.