Add an AJAX powered translation dropdown to allow incorporation of single string translations in-line in any editor instead of having to manage the translations separately in the translation manager.

Add the translation dropdown to a few fields in teh award sponsors, awards and award prizes.
This commit is contained in:
james 2006-09-19 22:40:46 +00:00
parent 0ebd709a13
commit 951f801093
7 changed files with 336 additions and 7 deletions

View File

@ -212,7 +212,7 @@ echo mysql_error();
echo "<input type=\"hidden\" name=\"id\" value=\"".$_GET['edit']."\">\n";
echo "<table>\n";
echo "<tr><td>".i18n("Name")."</td><td><input type=\"text\" name=\"name\" value=\"".htmlspecialchars($award_awards_name)."\" size=\"50\" maxlength=\"128\" /></td></tr>\n";
echo "<tr><td>".i18n("Name")."</td><td><input type=\"text\" id=\"name\" name=\"name\" value=\"".htmlspecialchars($award_awards_name)."\" size=\"50\" maxlength=\"128\" /><script type=\"text/javascript\">translateButton('name');</script></td></tr>\n";
echo "<tr><td>".i18n("Order")."</td><td><input type=\"text\" name=\"order\" value=\"".htmlspecialchars($award_awards_order)."\" size=\"5\" maxlength=\"5\" />(".i18n("presentation order").")</td></tr>\n";
echo "<tr><td>".i18n("Sponsor")."</td><td>";
$sq=mysql_query("SELECT id,organization FROM award_sponsors ORDER BY organization");
@ -247,7 +247,7 @@ echo mysql_error();
echo "</select>";
echo "</td></tr>";
echo "<tr><td>".i18n("Criteria")."</td><td><textarea name=\"criteria\" rows=\"8\" cols=\"50\">".htmlspecialchars($award_awards_criteria)."</textarea></td></tr>\n";
echo "<tr><td>".i18n("Criteria")."</td><td><textarea id=\"criteria\" name=\"criteria\" rows=\"4\" cols=\"50\">".htmlspecialchars($award_awards_criteria)."</textarea><script type=\"text/javascript\">translateButton('criteria');</script></td></tr>\n";
echo "<tr><td>".i18n("Eligibility")."</td><td>";
echo "<table>";

View File

@ -128,7 +128,7 @@
echo "<input type=\"hidden\" name=\"id\" value=\"".$_GET['edit']."\">\n";
echo "<table>\n";
echo "<tr><td>".i18n("Prize Description")."</td><td></td><td><input type=\"text\" name=\"prize\" value=\"".htmlspecialchars($r->prize)."\" size=\"40\" maxlength=\"128\" /></td></tr>\n";
echo "<tr><td>".i18n("Prize Description")."</td><td></td><td><input type=\"text\" id=\"prize\" name=\"prize\" value=\"".htmlspecialchars($r->prize)."\" size=\"40\" maxlength=\"128\" /><script type=\"text/javascript\">translateButton('prize');</script></td></tr>\n";
echo "<tr><td>".i18n("Cash Amount")."</td><td>\$</td><td><input type=\"text\" name=\"cash\" value=\"".htmlspecialchars($r->cash)."\" size=\"10\" maxlength=\"10\" /></td></tr>\n";
echo "<tr><td>".i18n("Scholarship Amount")."</td><td>\$</td><td><input type=\"text\" name=\"scholarship\" value=\"".htmlspecialchars($r->scholarship)."\" size=\"10\" maxlength=\"10\" /></td></tr>\n";
echo "<tr><td>".i18n("Number")."</td><td></td><td><input type=\"text\" name=\"number\" value=\"".htmlspecialchars($r->number)."\" size=\"3\" maxlength=\"5\" /></td></tr>\n";

View File

@ -26,9 +26,7 @@
auth_required('admin');
send_header("Administration - Award Sponsors");
?>
<?
echo "<a href=\"index.php\">&lt;&lt; ".i18n("Back to Administration")."</a>\n";
echo "<a href=\"awards.php\">&lt;&lt; ".i18n("Back to Awards")."</a>\n";
@ -105,7 +103,7 @@
echo "<input type=\"hidden\" name=\"id\" value=\"".$_GET['edit']."\">\n";
echo "<table>\n";
echo "<tr><td>".i18n("Organization Name")."</td><td><input type=\"text\" name=\"organization\" value=\"".htmlspecialchars($r->organization)."\" size=\"60\" maxlength=\"128\" /></td></tr>\n";
echo "<tr><td>".i18n("Organization Name")."</td><td><input type=\"text\" id=\"organization\" name=\"organization\" value=\"".htmlspecialchars($r->organization)."\" size=\"60\" maxlength=\"128\" /><script type=\"text/javascript\">translateButton('organization');</script></td></tr>\n";
echo "<tr><td>".i18n("Address")."</td><td><input type=\"text\" name=\"address\" value=\"".htmlspecialchars($r->address)."\" size=\"60\" maxlength=\"64\" /></td></tr>\n";
echo "<tr><td>".i18n("City")."</td><td><input type=\"text\" name=\"city\" value=\"".htmlspecialchars($r->city)."\" size=\"32\" maxlength=\"32\" /></td></tr>\n";
echo "<tr><td>".i18n("Province")."</td><td>";

39
admin/gettranslation.php Normal file
View File

@ -0,0 +1,39 @@
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
?>
<?
include "../common.inc.php";
auth_required('admin');
foreach($config['languages'] AS $l=>$ln)
{
if($l=="en") continue;
$q=mysql_query("SELECT * FROM translations WHERE lang='$l' AND strmd5='".md5($_GET['str'])."'");
if($r=mysql_fetch_object($q))
echo "$l:$r->val\n";
else
echo "$l:\n";
}
?>

40
admin/settranslation.php Normal file
View File

@ -0,0 +1,40 @@
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
?>
<?
include "../common.inc.php";
auth_required('admin');
foreach($config['languages'] AS $l=>$ln)
{
if($l=="en") continue;
//check if it exists;
$q=mysql_query("SELECT * FROM translations WHERE lang='$l' AND strmd5='".md5($_GET['str'])."'");
if(mysql_num_rows($q))
mysql_query("UPDATE translations SET val='".mysql_escape_string(stripslashes($_GET[$l]))."' WHERE lang='$l' AND strmd5='".md5($_GET['str'])."'");
else
mysql_query("INSERT INTO translations (lang,strmd5,str,val) VALUES ('$l','".md5($_GET['str'])."','".mysql_escape_string(stripslashes($_GET['str']))."','".mysql_escape_string(stripslashes($_GET[$l]))."')");
}
?>

View File

@ -392,6 +392,13 @@ function confirmChanges()
-->
</script>
<?
//if we're under /admin or /config we also want the translationDropdown javascript stuff
if(substr(getcwd(),-6)=="/admin" || substr(getcwd(),-7)=="/config")
require_once("../translationsdropdown.inc.php");
?>
<div id="header">
<?
if(file_exists($prependdir."data/logo-100.gif"))

View File

@ -0,0 +1,245 @@
<?
/*
This file is part of the 'Science Fair In A Box' project
SFIAB Website: http://www.sfiab.ca
Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
Copyright (C) 2005 James Grant <james@lightbox.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
?>
<script type="text/javascript">
function getHTTPObject()
{
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
try {
xmlhttp = new XMLHttpRequest();
} catch (e)
{
xmlhttp = false;
}
}
return xmlhttp;
}
var http=getHTTPObject();
var queryInProgress=false;
var translateOpen=false;
var translationObject;
var langstr="<? foreach($config['languages'] AS $l=>$ln){ $lstr.="$l/"; } echo substr($lstr,0,-1)?>";
var jsTranslateLangs=new Array();
<?
$x=0;
foreach($config['languages'] AS $l=>$ln)
{
if($l=="en")continue;
echo "jsTranslateLangs[$x]=\"$l\";\n";
$x++;
}
?>
function getTranslations(o)
{
var objItem=document.getElementById(o);
var url="<?=$config['SFIABDIRECTORY']?>/admin/gettranslation.php?str="+escape(objItem.value);
if(!queryInProgress)
{
queryInProgress=true;
http.open("GET", url , true);
http.onreadystatechange = handleResponse;
http.send(null);
}
}
function handleResponse()
{
try {
if(http.readyState==4)
{
queryInProgress=false;
var d=document.getElementById('translationdropdown');
// alert(completeField);
try {
results = http.responseText.split('\n');
var num=results.length;
for(i=0;i<results.length;i++)
{
if(!results[i]){ num--; continue; }
line = results[i].split(':');
//line[0] has "en" or "fr" or the lang code
//line[1] has the actual translation for that language
objInput=document.getElementById('translation['+line[0]+']');
if(line[1])
{
//alert(objInput);
objInput.value=line[1];
}
else
{
objInput.value="";
}
}
}
catch(e)
{
}
}
}
catch(e)
{
}
}
function translateButton(o)
{
document.write("<a href=\"#\" onclick=\"return translateDropdown('"+o+"')\"><?=i18n("translations")?></a>");
}
function translateDropdown(o)
{
translationObject=document.getElementById(o);
var d=document.getElementById('translationdropdown');
if(translateOpen)
d.style.visibility="hidden";
else
{
getTranslations(o);
objItem=translationObject;
var tagheight=objItem.offsetHeight;
var tagwidth=objItem.offsetWidth;
//alert('tagheight='+tagheight+' tagwidth='+tagwidth);
var intx=0;
var inty=0;
do
{
intx+=objItem.offsetLeft;
inty+=objItem.offsetTop;
objParent=objItem.offsetParent.tagName;
objItem=objItem.offsetParent;
} while(objParent!="BODY");
d.style.top=inty+tagheight+"px";
d.style.left=intx+"px";
d.style.width=tagwidth+"px";
// d.style.height=dropdownheight+"px";
d.style.visibility="visible";
oButton=document.getElementById('buttonsavetranslations');
oButton.value="<?=i18n("Save Translations")?>";
}
translateOpen=!translateOpen;
return false;
}
function savetranslations()
{
var url="<?=$config['SFIABDIRECTORY']?>/admin/settranslation.php?str="+escape(translationObject.value);
var x;
for(x=0;x<jsTranslateLangs.length;x++)
{
oTmp=document.getElementById('translation['+jsTranslateLangs[x]+']');
url+="&"+jsTranslateLangs[x]+"="+escape(oTmp.value);
}
oButton=document.getElementById('buttonsavetranslations');
oButton.value="<?=i18n("Saving translations...")?>";
if(!queryInProgress)
{
queryInProgress=true;
http.open("GET", url , true);
http.onreadystatechange = handleSaveResponse;
http.send(null);
}
return false;
}
function handleSaveResponse()
{
try {
if(http.readyState==4)
{
queryInProgress=false;
var d=document.getElementById('translationdropdown');
oButton=document.getElementById('buttonsavetranslations');
oButton.value="<?=i18n("Translations Saved")?>";
setTimeout("translateDropdown('dummy');",500); //it doesnt matter what obj we use, because we're just clearing it anyways
//who cares what happens, we're done thats all we care about
}
}
catch(e)
{
}
}
</script>
<?
$num=count($config['languages'])-1; //subtract 1 for english
$divheight=($num*30)+50;
?>
<div name="translationdropdown" id="translationdropdown" style="background-color: white; visibility: hidden; position: absolute; border: 1px solid grey; top:0px; left:0px; width:300px; height:<?=$divheight?>px; overflow: auto">
<form name="translationform" method="get">
<table width="95%">
<?
foreach($config['languages'] AS $l=>$ln)
{
if($l=="en") continue;
echo "<tr><td>$ln</td><td><input type=\"text\" style=\"width: 100%\" id=\"translation[$l]\" name=\"translation[$l]\"></td></tr>";
}
echo "<tr><td colspan=\"2\" align=\"center\"><input type=\"button\" id=\"buttonsavetranslations\" onclick=\"return savetranslations()\" value=\"".i18n("Save Translations")."\"></td></tr>";
?>
</table>
</form>
</div>