[Edit (11/06): The mods described below, which apply to the templates and the language files, as well as mods that will allow dbase entry switches, are apparently being put into the core files of v1.6. If you apply the mods below, which do not involve dbase tinkering, you will not need to move them forward to v1.6. Also, since my dbase mods may not be the same as those put in place by the core developers, I will not publish them here, but am happy to share them privately with anyone who cannot wait for 1.6 and who is prepared to adjust once 1.6 comes out.]
I have hacked PP to allow a user to switch between French and English in a manner that switches the language files and the templates, but still not the dbase entries (which is way beyond my cut and paste skills). For anyone interested, here is my hack. Note that I put everything in the index.php (I know Connie, I shouldn't) because I couldn't get anything to work as includes.
Step 1: (After backing up index.php) I put this near the top of the index.php after the requires. It collects and sets the language preference and prepares the variables:
PHP Code:
// #########################################
// Language Switch Hack 1 - capture language preferences
// #########################################
// Set the default language.
$defaultlanguage = "en";
// Set $getlang to the requested language if a GET arg 'lang' exists.
$getlang = $_GET['lang'];
// Set a cookie to the GET arg 'lang' if it exists.
if ( isset ($getlang) ) {
setcookie ('lang', $getlang, false, '/', false, 0);
}
// Set the SESSION key 'lang' to the 'lang' value of the cookie if it exists.
if ( isset ($_COOKIE['lang']) ) {
$_SESSION['lang'] = $_COOKIE['lang'];
}
// Set the &language variable to session 'lang' - this variable is the one used below
$language = $_SESSION['lang'];
// Use the default language if none of the previous steps captured a language preference
if ( !isset ($language) ) {
$language = $defaultlanguage;
}
// let $_GET['lang'] override the default
if ( isset ($getlang) ) {
$language = $getlang;
$_SESSION['lang'] = $language;
}
// convert the two letter $language variable to full name of language file (used in language file switch but not template switch)
$expand_language = array(
"en" => "english",
"fr" => "french",
);
$setlang = $expand_language[$language];
// ############################################
// END hack for language switch. $language variable now set by either cookie, GET or default.
// ###########################################
Step 2: I changed the code for including the language file, commenting out the old code and replacing it with new code that really only adds the $setlang variable to the language file include
PHP Code:
//#####################################
// Language Switch Hack to get the language file (old language set commented out / new lines include references to $setlang added in)
//#####################################
//if (file_exists("language/lang-".$cfgrow['langfile'].".php") )
//{
// if ( !isset($_GET['x'])OR($_GET['x'] != "rss" & $_GET['x'] != "atom"))
// require("language/lang-".$cfgrow['langfile'].".php");
//}
//else
//{
// echo '<b>Error:</b><br />No <b>language</b> folder exists or the file <b>"lang-' .$cfgrow['langfile'] .'.php"</b> is missing in that folder.<br />Make sure that you have uploaded all necessary files with the exact same names as mentioned here.';
// exit;
//}
if (file_exists("language/lang-".$setlang.".php") )
{
if ( !isset($_GET['x'])OR($_GET['x'] != "rss" & $_GET['x'] != "atom"))
require("language/lang-".$setlang.".php");
}
else
{
echo '<b>Error:</b><br />No <b>language</b> folder exists or the file <b>"lang-' .$setlang.'.php"</b> is missing in that folder.<br />Make sure that you have uploaded all necessary files with the exact same names as mentioned here.';
exit;
}
// ########################################
// END get language file - End language switch hack
// ########################################
Step 3: I changed the code for the template include by inserting the $language variable in the template (See step 5 below on how to create two versions of each template - one for each language).
PHP Code:
//########################################
// Language Switch Hack - Change template and set template language (Hack involves inserting $language variable)
//########################################
if( isset($_GET['x'])&&file_exists( "templates/".$cfgrow['template']."/".$_GET['x']."_".$language."_template.html" ) )
{
if (eregi("[.]",$_GET['x']))
die("Come on! forget about it...");
$tpl = file_get_contents("templates/".$cfgrow['template']."/".$_GET['x']."_".$language."_template.html");
}
else
{
if (!file_exists("templates/".$cfgrow['template']."/image_".$language."_template.html"))
{
echo '<b>Error:</b><br />No template folder exists by the name of <b>"' .$cfgrow['template'] .'"</b> or the file <b>image_'.$language .'_template.html</b> is missing in that folder.<br />Make sure that you have uploaded all necessary files with the exact same names as mentioned here.';
exit;
}
// if the x=foo does not exist prompt it! don't show the main page anymore!
if (isset($_GET['x'])&& $_GET['x']!='atom' && $_GET['x']!='rss' && $_GET['x']!='save_comment' ){ // if (isset($_GET['x']) and !file_exists( "templates/".$cfgrow['template']."/".$_GET['x']."_template.html" ))
header("HTTP/1.0 404 Not Found");
header("Status: 404 File Not Found!");
// header("Location: index.php");
echo "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML><HEAD>\n<TITLE>404 Not Found</TITLE>\n</HEAD><BODY>\n<H1>Not Found</H1>\nThe requested URL /index.php was not found on this server.<P>\n<P>Additionally, a 404 Not Found\nerror was encountered while trying to use an ErrorDocument to handle the request.\n</BODY></HTML>";
exit;
}
$tpl = file_get_contents("templates/".$cfgrow['template']."/image_".$language."_template.html");
}
if(isset($_GET['popup'])&&$_GET['popup'] == "comment")
{
$tpl = file_get_contents("templates/".$cfgrow['template']."/comment_".$language."_template.html");
}
// #########
// END HACK FOR LANGUAGE TEMPLATE SWITCH
// #########
Step 4: I created a TAG to be placed on all templates that adds the new lang request to the existing url. (I made a request in an earlier post for assistance with this but don't think I was clear enough in my request to get any takers). I am sure there is a cleaner way to do this, but here is what I came up with (I put it near the bottom of the index file, with the other tags):
PHP Code:
// ###################################//
// Language switch hack - create a template tag for link to switch the language setting
// #######################################//
// Reverse the language instruction
$switchlanguage = array(
"en" => "fr",
"fr" => "en",
);
$targetlanguage = $switchlanguage[$language];
// Expand the language query to full word for link
$expand_language_link = array(
"en" => "English",
"fr" => "Français",
);
$setlinklang = $expand_language_link[$targetlanguage];
// If the query string is empty or already contains only previous language query, only need to pass the new language query
if (($_SERVER["QUERY_STRING"] == "")OR($_SERVER["QUERY_STRING"] == "lang=".$language))
$ch_lang = "<a href='".$PHP_SELF."?lang=".$targetlanguage."'>".$setlinklang."</a>";
else
// If the query string is not empty, collect all the elements of the query for reassembly with new language query
{
// Extract queries on "browse" and "about" pages and other custom pages
if( isset($_GET['x']))
{
$templatequery = "x=".$_GET['x'];
if( isset($_GET['category']))
$categoryquery = "&category=".$_GET['category'];
else
$categoryquery = "";
if( isset($_GET['archivedate']))
$archivequery = "&archivedate=".$_GET['archivedate'];
else
$archivequery = "";
// reassemble the query with the new language instruction
$ch_lang = "<a href='".$PHP_SELF."?".$templatequery.$categoryquery.$archivequery."&lang=".$targetlanguage."'>".$setlinklang."</a>";
}
else
// Extract queries on "image" page with GeoS Browse addon enabled
{
$imagequery = "showimage=".$_GET['showimage'];
if( isset($_GET['category']))
$categoryquery = "&category=".$_GET['category'];
else
$categoryquery = "";
// reassemble the query with the new language instruction
$ch_lang = "<a href='".$PHP_SELF."?".$imagequery.$categoryquery."&lang=".$targetlanguage."'>".$setlinklang."</a>";
}
}
// Create one template tag for all templates and both languages
$tpl = str_replace("<CH_LANG>",$ch_lang,$tpl);
Step 5: As mentionned above in setp 3, I created two copies of all templates and inserted the language abbreviation in the middle: "image_en_template.html", "image_fr_template.html", etc. Of course, the content of each template is in the language indicated.
Step 6 (ongoing): I am searching out all remaining single language items in the index code and in addons that I use and transferring them to the language files.
Step 7 (future): convince someone with some spare time (and more MySQL and PHP skills than I) to create a PixelFish addon, one that creates two mirror dbase tables, one with entries for second language versions of the categories, and one with entries for second language versions of the Title and Notes fields, associatied by image number and called depending on language preference. :-)
My dev site, where there is also a working version of GeoS' restricted browse addon, is at
http://photoblog.sophiepasquet.com. I don't promise that there are no kinks yet to iron out, but feedback is welcome.
Rob