*Works with
all 4images versions*
This MOD was created by Jan, but never "officialy" was published:
http://www.4homepages.de/forum/index.php?topic=3351.0(and I'm getting PMs very often with questions how did I do that.)
------ Overview -------------------
With this MOD your site visitors will be able chose language for the interface.
There are two versions of this MOD:
A: Using dropdown menu
B: Using images/text as links
----- Installation -------------------
Step 1.--- Version
A ---
Open
/includes/page_header.phpFind:
$site_template->register_vars(array(
"media_url" => MEDIA_PATH,
"thumb_url" => THUMB_PATH,
Add before:
$query_string = '';
if (!empty($HTTP_GET_VARS)) {
foreach ($HTTP_GET_VARS as $key => $val) {
if ($key != "l") {
$query_string .= ($query_string != '' ? '&' : '?').$key."=".$val;
}
}
}
// We add the session id with "&" not "&"
$lang_url = $site_sess->url($PHP_SELF.$query_string, '&');
// Now we can better remove the "l" parameter
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
// We replace "&" with "&" to make it valid XHTML
$lang_url = str_replace("&", "&", $lang_url);
$lang_select = "<form action=\"".$lang_url."\" method=\"post\">\n";
$lang_select .= "<select class=\"select\" name=\"l\" onChange=\"submit()\">\n";
// Now we open the "lang" folder, read out all available languages
// and add it as options to the dropdown.
$handle = opendir(ROOT_PATH."lang");
while ($folder = @readdir($handle)) {
if (@is_dir(ROOT_PATH."lang/".$folder) && $folder != "." && $folder != "..") {
$lang_select .= "<option value=\"".$folder."\"";
// If the folder name matches the current language,
// show the option as selected
if ($folder == $config['language_dir']) {
$lang_select .= " selected=\"selected\"";
}
$lang_select .= ">".$folder."</option>\n";
}
}
$lang_select .= "</select>\n</form>";
// Register the dropdown code for the template engine
$site_template->register_vars("lang_select", $lang_select);
--- Version
B ---
Open
/includes/page_header.phpFind:Find:
$site_template->register_vars(array(
"media_url" => MEDIA_PATH,
"thumb_url" => THUMB_PATH,
Add before:
$query_string = '';
if (!empty($HTTP_GET_VARS)) {
foreach ($HTTP_GET_VARS as $key => $val) {
if ($key != "l") {
$query_string .= ($query_string != '' ? '&' : '?').$key."=".$val;
}
}
}
$lang_url = $site_sess->url($PHP_SELF.$query_string, '&');
$lang_url = preg_replace("'&(amp|#38);'i", "&", $lang_url);
$lang_url = preg_replace("/[?|&]l=[^?|&]*/", "", $lang_url);
$lang_url = str_replace("&", "&", $lang_url);
$handle = opendir(ROOT_PATH."lang");
$lang_select = "";
while ($folder = @readdir($handle)) {
if (@is_dir(ROOT_PATH."lang/".$folder) && $folder != "." && $folder != "..") {
if ($folder != $config['language_dir']) {
$lang_select .= "<a class=\"lang\" href=\"".$lang_url.(preg_match("/english/i",$folder) ? "" : ((preg_match("/\?/", $lang_url) ? "&" : "?")."l=".$folder))."\" onMouseOver=\"(window.status='$folder'); return true\" onMouseOut=\"window.status=''; return true\"><img src=\"".TEMPLATE_PATH."/images/".$folder.".gif\" border=\"0\" alt=\"".$folder."\"></a> ";
}else{
$lang_select .= "<img src=\"".TEMPLATE_PATH."/images/".$folder."2.gif\" border=\"0\" alt=\"".$folder."\"> ";
}
}
}
// Register the dropdown code for the template engine
$site_template->register_vars("lang_select", $lang_select);
Step 2. (for both versions)
Open a temlate where u want your language selector be showed (i.e.
/templates/<yourtemplate>/home.html) and add this tag:
{lang_select}------- Final -----------------------
This script scans
/lang/ folder and if it finds any folders inside it, it will add them in the selection.
------- Note ------------------------
Version
B is set to use images (I use it on my site)
the filenames of images must be this format:
language_folder_name.gif - for
not currently selected languages
and
language_folder_name2.gif - for currently selected language
This version is based on sessions, that means as soon as browser is closed, the language sellection will be lost.
If u wish have
cookies based version, so it would "remmember" the last selected language, then u will need apply these changes:
http://www.4homepages.de/forum/index.php?topic=4743.msg31555#msg31555