PDA

View Full Version : Bilingual PixelPost (almost)


RobbieMc
03-23-2006, 04:44 AM
[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:


// #########################################
// 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


//#####################################
// 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).


//########################################
// 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):

// ###################################//
// 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.php?x=downloads&page=mod
there

raminia
04-09-2006, 05:02 AM
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
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

RobbieMc
05-13-2006, 12:35 AM
Christoph, the instructions at the beginning of this thread will get you 2/3 of the way to a bilingual PP (although I would also be interested in how phoetic.de pulled it off). I am waiting to get the 1.5 Final before transferring all my language hacks to the index.php file.

My wife's site is an example of the script above: http://photoblog.sophiepasquet.com

Rob

mykodachrome
05-14-2006, 04:20 AM
I am trying to get this (http://labnol.blogspot.com/2005/11/add-language-translation-to-website.html) to work for translation on my test site (http://www.mykodachrome.com/pixelpost0001/) but so far no luck. Surely this should be possible. I know it will not be a real bilingual site, but it would be cool!

christoph
05-26-2006, 11:05 AM
Hi all,

sorry for my late answer. I thought I would get an email when my post was answered, but obviously I didn't subscribe to the notification option - my mistake ;)

@ Rob - I'm not afraid of some work to get the whole thing working like on your wife's blog (nice!). It's just the fact that - as far as I understood - I likely will have some (or even many) problems with each pp-update I will do in the future because I have to change the pp's system files for the above. Because of that it would just be very much smarter to have it as an addon but I just don't get how to make one out of that :confused:

@ mykodachrome - I'm not realy convinced about that... have you ever checked the translations? (Some extra-fun if your native language is NOT english of course.) As long as this kind of automatical translation makes anybody more laugh than understand I would prefer to know exactly what the visitors of my blog will get to read on my page :)

Best regards from Belgium,
Chris

RobbieMc
05-26-2006, 01:15 PM
Chris, I will try to move as much of it as I can to an addon in the future, but some parts I don't think can be moved to an addon (eg, the template switch). I will post the entire set of php files (index.php and addon files) once 1.5 Final has come out and I transfer the changes to there. I'll let you know when I post it.

Rob

christoph
05-26-2006, 04:07 PM
Thanks a lot, Rob. I look forward to your solution when 1.5 Final has released. I will continue thinking about it too. There must be a simple workaround which I didn't figure out yet ;)

Have a nice day,
Chris

GeoS
05-26-2006, 08:41 PM
One of future versions of Pixelpost will have user's workspaces so it will be much easier to do such things as addons :D

RobbieMc
11-07-2006, 01:45 AM
I have now transferred all of these hacks to PP 1.5 Final, including those that hack the admin for switches of certain dbase entries. However, it requires new dbase fields (2 in pixelpost table and 1 in category table). I understand that I could probably write an "install" script that created these new fields tables, but after spending 18 hours on the weekend transferring the hacks, I think I am now out of PP coding steam. I am happy to share the hacked core files with anybody who wants them, but you will be on your own using phpmyadmin to create the needed dbase fields (I will indicate which ones need to be created).

I understand that 1.6 will be bilingual so this interim fix is not needed for those who are preared to wait.

Rob

Dennis
11-18-2006, 01:07 PM
I understand that 1.6 will be bilingual so this interim fix is not needed for those who are preared to wait.


We are trying to make pixelpost bilingual and currently the code is under review.

klimin_a_s
11-19-2006, 01:10 PM
We are trying to make pixelpost bilingual and currently the code is under review.

I am waiting 1.6! Bilingual functionality is very cool feature for all non-english photoblogs!

Can you say an estimation date of the 1.6 release?

Dennis
11-19-2006, 02:15 PM
Can you say an estimation date of the 1.6 release?

Nope, the release date is still under review. :)

GeoS
11-19-2006, 09:05 PM
There are huge plans for this version so it is really hard to say when it will be ready for release.