Designate Search language on the fly

Post Reply
User avatar
captquirk
Site Admin
Posts: 103
Joined: Sun Apr 09, 2017 8:49 pm
Location: Arizona, USA
Contact:

Designate Search language on the fly

Post by captquirk » Thu Dec 13, 2018 6:30 pm

If you want to present the search page in a language other than the language setup from the administration paqnel, this simple modification will do the trick.

Edit search.php. Very near the top, change
error_reporting(0);
$include_dir = "./include";
to
error_reporting(0);
session_start();
$include_dir = "./include";
Next, in the same file, scroll down to where you see
if (isset($_REQUEST['date3'])) {
$date3 = strip_tags($_REQUEST['date3']);
}

$include_dir = "./include";
You will want to add 5 lines. You will end up with
if (isset($_REQUEST['date3'])) {
$date3 = strip_tags($_REQUEST['date3']);
}
if (isset($_REQUEST['sl'])) {
$sl = strip_tags($_REQUEST['sl']);
} else {
$sl = $_SESSION['sl'];
}

$include_dir = "./include";
Go down about 10 lines and find
require $settings_dir."/conf.php";
require $include_dir."/detectmobilebrowser.php";
Add 4 lines, resulting in
require $settings_dir."/conf.php";
if ($sl == '') {
$sl = $language;
}
$_SESSION['sl'] = $sl;
require $include_dir."/detectmobilebrowser.php";
Go further down and there are three functions [ function tab1(), function tab2(), and function tab3() ]. In each of these three functions, you will see several lines of globals. You want to add $sl to each function as a global. An example with $sl added is
global $results, $start, $adv, $sl;
Not every line starting with "global" needs this... only once in each function.

Finally, in each of the three functions, see the line
include $settings_dir."/conf.php";
Add a line after, resulting in
include $settings_dir."/conf.php";
$language=$sl;
Save and exit. The modification is complete.

To use the modification, you add a command-line parameter when initially calling search.php. For example, you have English set as the Sphider default. a href='search.php" will bring up the search page in the default English. However, if you wish to show the page in Spanish, use href="search.php?sl=es". The search page will be in Spanish until the end of the session (or you call another language for another language such as href="search.php?en" to revert back to English. If you are doing the call via a form, use action="search.php?sl=de" to bring up the search in German.

Post Reply