Updated and working translations dropdown - simply add class="translatable" anywhere you want something translated

This commit is contained in:
james 2009-09-11 05:16:37 +00:00
parent 54739b72b5
commit d17de3f6e6
4 changed files with 101 additions and 27 deletions

View File

@ -397,9 +397,7 @@ $(document).ready(function() {
<input type="hidden" name="id" id="awardinfo_id" value="0" />
<table class="tableedit">
<tr><td class="left"><?=i18n("Name")?>:</td>
<td class="right"><input type="text" id="awardinfo_name" name="name" value="Loading..." size="50" maxlength="128">
<script type="text/javascript">translateButton('name');</script>
</td></tr>
<td class="right"><input class="translatable" type="text" id="awardinfo_name" name="name" value="Loading..." size="50" maxlength="128"> </td></tr>
<tr><td class="left"><?=i18n("Order")?>:</td>
<td class="right"><input type="text" id="awardinfo_order" name="order" value="" size="5" maxlength="5" />(<?=i18n("presentation order")?>)
</td></tr>
@ -429,9 +427,9 @@ $(document).ready(function() {
?>
</select></td></tr>
<tr><td class="left"><?=i18n("Criteria")?>:</td>
<td class="right"><textarea id="awardinfo_criteria" name="criteria" rows="3" cols="50">Loading...</textarea><script type="text/javascript">translateButton('criteria');</script></td></tr>
<td class="right"><textarea class="translatable" id="awardinfo_criteria" name="criteria" rows="3" cols="50">Loading...</textarea></td></tr>
<tr><td class="left"><?=i18n("Description")?>:</td>
<td class="right"><textarea id="awardinfo_description" name="description" rows="3" cols="50">Loading...</textarea><script type="text/javascript">translateButton('description');</script></td></tr>
<td class="right"><textarea class="translatable" id="awardinfo_description" name="description" rows="3" cols="50">Loading...</textarea></td></tr>
</table>
<h2>Options</h2>
@ -515,7 +513,7 @@ $(document).ready(function() {
<input type="hidden" id="prizeinfo_award_awards_id" name="award_awards_id" value=""/>
<table class="tableedit">
<tr> <td class="left"><?=i18n("Prize Description")?>:</td>
<td class="right"><input type="text" id="prizeinfo_prize" class="prizeinfo" name="prize" value="" size="40" maxlength="128" disabled="disabled"/><script type="text/javascript">translateButton('prize');</script></td>
<td class="right"><input type="text" id="prizeinfo_prize" class="prizeinfo translatable" name="prize" value="" size="40" maxlength="128" disabled="disabled"/></td>
</tr><tr>
<td class="left"><?=i18n("Cash Amount")?> ($):</td>
<td class="right"><input type="text" id="prizeinfo_cash" class="prizeinfo" name="cash" value="" size="10" maxlength="10" disabled="disabled" /></td>

View File

@ -23,18 +23,17 @@
?>
<?
include "../common.inc.php";
require_once("../user.inc.php");
require_once("../user.inc.php");
user_auth_required('committee', 'admin');
foreach($config['languages'] AS $l=>$ln)
{
if($l=="en") continue;
$ret=array();
foreach($config['languages'] AS $l=>$ln) {
if($l==$config['default_language']) 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";
$ret[$l]=$r->val;
else
echo "$l:\n";
$ret[$l]="";
}
echo json_encode($ret);
?>

View File

@ -25,17 +25,23 @@
include "../common.inc.php";
require_once("../user.inc.php");
user_auth_required('committee', 'admin');
foreach($config['languages'] AS $l=>$ln)
{
if($l=="en") continue;
print_r($_POST);
foreach($config['languages'] AS $l=>$ln) {
if($l==$config['default_language']) 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]))."')");
$m=md5($_POST['translate_str_hidden']);
if($_POST['translate_'.$l]) {
$q=mysql_query("SELECT * FROM translations WHERE lang='$l' AND strmd5='$m'");
if(mysql_num_rows($q))
mysql_query("UPDATE translations SET val='".mysql_real_escape_string(stripslashes($_POST['translate_'.$l]))."' WHERE lang='$l' AND strmd5='$m'");
else
mysql_query("INSERT INTO translations (lang,strmd5,str,val) VALUES ('$l','$m','".mysql_real_escape_string(stripslashes($_POST['translate_str_hidden']))."','".mysql_escape_string(stripslashes($_POST['translate_'.$l]))."')");
}
else {
mysql_query("DELETE FROM translations WHERE lang='$l' AND strmd5='$m'");
}
}
?>

View File

@ -22,20 +22,91 @@
?>
<script type="text/javascript">
var currentLang='<?=$_SESSION['lang']?>';
var translateLangs=new Array();
<?
$x=0;
foreach($config['languages'] AS $l=>$ln) {
if($l==$_SESSION['lang']) continue;
echo "translateLangs[$x]=\"$l\";\n";
$x++;
}
?>
$(document).ready(function() {
$(".translatable").each( function(i) {
$(this).after("<a href=\"#translate#"+this.id+"\"><?=i18n("translation")?></a>");
$(this).after(" <a href=\"#translate\"><?=i18n("translations")?></a>");
});
$("[href*=#translate#]").click(function() {
$("#translationdialog").dialog();
$("[href*=#translate]").click(function() {
// alert(this.href);
// $("#translationdialog").dialog({ buttons: { "Save": function() { $(this).dialog("close");}}, modal: true });
// alert($(this).prev().attr('id'));
popup_translator($(this).prev().val());
return false;
});
$("#translation_editor").dialog({
bgiframe: true, autoOpen: false,
modal: true, resizable: false,
draggable: false
});
});
function popup_translator(str) {
var w = (document.documentElement.clientWidth * 0.8);
var h = (document.documentElement.clientHeight * 0.4);
$('#translation_editor').dialog('option','width',w);
$('#translation_editor').dialog('option','height',h);
$('#translation_editor').dialog('option','buttons',{ "<?=i18n("Save")?>": function() { save_translations(); },
"<?=i18n("Cancel")?>": function(){ $(this).dialog("close");}});
$('#translation_editor').dialog('open');
$('#translate_str').html(str);
$('#translate_str_hidden').val(str);
$.getJSON("<?=$config['SFIABDIRECTORY']?>/admin/gettranslation.php?str="+escape(str),function(json){
for(var i=0;i<translateLangs.length;i++) {
$("#translate_"+translateLangs[i]).val(json[translateLangs[i]]);
}
});
return false;
}
function save_translations() {
$.post("<?=$config['SFIABDIRECTORY']?>/admin/settranslation.php",
$("#translationform").serialize(),
function(data) {
$('#translation_editor').dialog('close');
});
return false;
}
//this is here only to catch any missing translateButton()'s
function translateButton(o) {
// alert('tell james there is a translateButton he missed');
}
</script>
<div style="display: none" id="translationdialog">This is the translation dialog</div>
<div style="display: none" title="<?=i18n("Translation Editor")?>" id="translation_editor">
<form id="translationform" onsubmit="return save_translations()">
<input type="hidden" id="translate_str_hidden" name="translate_str_hidden">
<table style="width: 100%;">
<?
echo "<tr><td align=\"right\" width=\"100\">".$config['languages'][$config['default_language']].":</td><td><span id=\"translate_str\" style=\"font-weight: bold;\"></span></td></tr>\n";
echo "<tr><td colspan=\"2\"><hr /></td></tr>\n";
foreach($config['languages'] AS $l=>$ln) {
if($l==$config['default_language']) continue;
echo "<tr><td align=\"right\">$ln</td><td><input style=\"width: 100%;\" type=\"text\" name=\"translate_{$l}\" id=\"translate_{$l}\"></td></tr>\n";
}
?>
</table>
</form>
</div>