Pixelpost Forum

Pixelpost Forum (http://www.pixelpost.org/forum/index.php)
-   Hacks and Modifications (http://www.pixelpost.org/forum/forumdisplay.php?f=16)
-   -   Bilingual PixelPost (almost) (http://www.pixelpost.org/forum/showthread.php?t=3668)

RobbieMc 03-23-2006 04:44 AM

Bilingual PixelPost
 
[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'$getlangfalse'/'false0);
}

// 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&ccedil;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 "&amp;category=".$_GET['category'];
        else
            
$categoryquery "";
            
        if( isset(
$_GET['archivedate']))
            
$archivequery "&amp;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 "&amp;category=".$_GET['category'];
        else
            
$categoryquery "";
    
        
// reassemble the query with the new language instruction        
        
$ch_lang "<a href='".$PHP_SELF."?".$imagequery.$categoryquery."&amp;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

RobbieMc 03-25-2006 08:17 AM

I have now also hacked the admin files to create bilingual database entries that are also switchable. I made the changes directly to the index files, but maybe when I upgrade to 1.5RC1, I will take the time to try and develop it as an addon.

http://photoblog.sophiepasquet.com

Connie 03-25-2006 09:10 AM

Robbie,

I aprreciate your work very much and it would be a great progress to have that as an admin addon

it will be a lot less hassle with upgrades ;=)

looking forward to have that addon,

Connie

RobbieMc 04-08-2006 04:03 PM

Connie, I have tried to convert the above into an addon, in anticipation of 1.5, but most of the elements above seem to need to be run at the beginning of the script, and it seems addons are run at the end. I can get three of the four parts into an include, but even there the template switch code won't work as an include.

Thanks for any suggestions.

phild 04-08-2006 04:51 PM

Félicitations ! | Well done !

The addon will be great…

RobbieMc 04-08-2006 08:53 PM

As I said in an earlier post, I modified the admin index to allow for bilingual dbase entries. Here is what my admin panel now looks like for images:

http://photoblog.sophiepasquet.com/spadmin.jpg

I know I could set up an addon that allowed access to the second language entries through a separate panel, but my question is whether it is possible to integrate these changes the way I have above (that is, in the image control panel) via an addon?

Thanks for any help.

Rob

raminia 04-08-2006 09:45 PM

cool...

btw, check it for intrusions by bots, overwriting $_COOKIE

raminia 04-09-2006 05:01 AM

Please sign in/up as a developer to www.Pixelpost.org/v1 and upload the modified files as modification to Pixelpost. it will be available at
http://www.pixelpost.org/v1/index.ph...loads&page=mod
there

raminia 04-09-2006 05:02 AM

Quote:

Originally Posted by RobbieMc
I know I could set up an addon that allowed access to the second language entries through a separate panel, but my question is whether it is possible to integrate these changes the way I have above (that is, in the image control panel) via an addon?

Thanks for any help.

Rob

yes

christoph 05-12-2006 03:17 PM

Any news about that?
 
Hi all!

I'm new to Pixelpost (tested it yesterday - very smart - cool) but a multi-lingual addon would make it perfect. Any news about that? I ran a forum search and it seems as if there are quite a lot of people looking for (or even thinking about) a solution. But finally nobody went through with it :o I think wow_ka must have found a good approach here: http://forum.pixelpost.org/showthread.php?t=1964 because the language switch on his homepage (http://www.phoetic.de/) is exactly what I'm looking for but finally the thread ends up *cry*

Best regards from Belgium,
Chris


All times are GMT. The time now is 09:27 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.