This script will help you to compare the latest english xml file with the oldest/newest spanish xml file. Once the script is configured and executed it will show on the left side the values for the english file and on the right the spanish ones, you just need to check, modify or add the ones you see empty and submit the form. Next you only need to copy/paste the output to a xml file and upload it to SupportSuite. Kayako's coders should do something like that for all the languages, that way it's easier to keep updated language files.
Usage:
Copy the code bellow, save it on a web visible directory as a php file, upload on the same dir the english and spanish xml file, edit the variables $file1 and $file2 on the php script and execute it.
Este script te ayudará a comparar el último archivo xml en inglés con el mas viejo/nuevo archivo xml en español. Una vez que el script. Una vez que el script ha sido configurado y ejecutado mostrará en el lado izquierdo los valores del archivo en inglés y en la derecha los del español, sólo necesitas verificar, modificar o agregar los que veas vacíos y enviar la forma. A continuación sólo necesitas copiar/pegar el resultado en un archivo xml y subirlo a SupportSuite. Los programadores de Kayako deberían hacer algo semejante para todos los lenguajes, así será más fácil mantener actualizados los archivos de lenguajes.
Uso:
Copia el código de abajo, guárdalo en un directorio visible en la web como un archivo php, sube al mismo directorio los archivos xml de inglés y español, edita las variables $file1 y $file2 en el script php y ejecútalo.
PHP Code:
<?
/*
Coded by: Mauricio Terrats <mterrats@gmail.com>
Feel free to modify it, keep credits ;)
*/
// $file1 should be the current english xml file (exported) provided by a fresh Kayako's SupportSuite installation
$file1 = "english.xml";
// $file2 should be the INCOMPLETE spanish xml file provided by disenioweb on Kayako's forums
// forum link: http://forums.kayako.com/showthread.php?t=3971
// spanish file: http://forums.kayako.com/attachment.php?attachmentid=156&d=1121430898
$file2 = "spanish.xml";
if ($_REQUEST[page] == "go") { do_magic(); exit; }
$content1 = xml2ary(file_get_contents($file1));
$content2 = xml2ary(file_get_contents($file2));
?>
<html><head><title>no title</title></head><body>
<form method="post">
<input type="hidden" name="page" value="go">
<table>
<?
parse_table1($content1['swiftlanguage']['_c'],$content2['swiftlanguage']['_c']);
parse_table2($content1['swiftlanguage']['_c']['phrase'],$content2['swiftlanguage']['_c']['phrase']);
?>
</table><br>
<input type="submit" value="Do some magic please ;)">
</form>
</body>
</html>
<?
exit;
// parses 1st level
function parse_table1($data1="",$data2="") {
if (!$data1) return;
foreach($data1 as $k => $v) {
if (!$v['_v']) continue;
?>
<tr>
<td><?=$k?></td><td><textarea name="swiftlanguage1[_c][<?=$k?>]"><?=$v['_v']?></textarea></td>
<td><textarea name="swiftlanguage2[_c][<?=$k?>][_v]"><?=$data2[$k]['_v']?></textarea></td>
</tr>
<?
}
}
// parses phrases
function parse_table2($data1="",$data2="") {
if (!$data1) return;
foreach($data1 as $k => $v) {
// because of lang lines are not ordered, we'll need to walk through $data2 lines each $data1 line.
// lazy code but works ;)
$tmpmatch = "";
foreach ($data2 as $k2 => $v2) {
if ($v['_a']['code'] == $v2['_a']['code']) { $tmpmatch = $v2; break; }
}
$tmphidden .= "<input type=\"hidden\" name=\"swiftlanguage2[_c][phrase][$k][_a][section]\" value=\"".$v['_a']['section']."\">\n";
$tmphidden .= "<input type=\"hidden\" name=\"swiftlanguage2[_c][phrase][$k][_a][code]\" value=\"".$v['_a']['code']."\">\n";
?>
<tr>
<td><?=$v['_a']['code']?> (<?=$v['_a']['section']?>)</td><td><textarea name="swiftlanguage1[_c][phrase][<?=$k?>]" cols="50" rows="10"><?=htmlentities($v['_v'])?></textarea></td>
<td><textarea name="swiftlanguage2[_c][phrase][<?=$k?>][_v]" cols="50" rows="10"><?=htmlentities(utf8_decode($tmpmatch['_v']))?></textarea></td>
</tr>
<?
}
// finally print complementary hidden values :)
echo $tmphidden;
}
// magic :D
function do_magic() {
header('Content-type: text/plain');
$tmparray['swiftlanguage'] = $_REQUEST['swiftlanguage2'];
$output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$output .= "<!-- XML Generated On: ".date("d m Y H:i:s")." -->\n";
$output .= ary2xml($tmparray);
echo $output;
}
// BIG Thanks to LeoSr http://mysrc.blogspot.com/2007/02/php-xml-to-array-and-backwards.html
// it has a small mod, find it!
function xml2ary(&$string) {
$parser = xml_parser_create();
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parse_into_struct($parser, $string, $vals, $index);
xml_parser_free($parser);
$mnary=array();
$ary=&$mnary;
foreach ($vals as $r) {
$t=$r['tag'];
if ($r['type']=='open') {
if (isset($ary[$t])) {
if (isset($ary[$t][0])) $ary[$t][]=array(); else $ary[$t]=array($ary[$t], array());
$cv=&$ary[$t][count($ary[$t])-1];
} else $cv=&$ary[$t];
if (isset($r['attributes'])) {foreach ($r['attributes'] as $k=>$v) $cv['_a'][$k]=$v;}
$cv['_c']=array();
$cv['_c']['_p']=&$ary;
$ary=&$cv['_c'];
} elseif ($r['type']=='complete') {
if (isset($ary[$t])) { // same as open
if (isset($ary[$t][0])) $ary[$t][]=array(); else $ary[$t]=array($ary[$t], array());
$cv=&$ary[$t][count($ary[$t])-1];
} else $cv=&$ary[$t];
if (isset($r['attributes'])) {foreach ($r['attributes'] as $k=>$v) $cv['_a'][$k]=$v;}
$cv['_v']=(isset($r['value']) ? $r['value'] : '');
} elseif ($r['type']=='close') {
$ary=&$ary['_p'];
}
}
_del_p($mnary);
return $mnary;
}
// _Internal: Remove recursion in result array
function _del_p(&$ary) {
foreach ($ary as $k=>$v) {
if ($k==='_p') unset($ary[$k]);
elseif (is_array($ary[$k])) _del_p($ary[$k]);
}
}
// Array to XML
function ary2xml($cary, $d=0, $forcetag='') {
$res=array();
foreach ($cary as $tag=>$r) {
if (isset($r[0])) {
$res[]=ary2xml($r, $d, $tag);
} else {
if ($forcetag) $tag=$forcetag;
$sp=str_repeat("\t", $d);
$res[]="$sp<$tag";
if (isset($r['_a'])) {foreach ($r['_a'] as $at=>$av) $res[]=" $at=\"$av\"";}
$res[]=">".((isset($r['_c'])) ? "\n" : '');
if (isset($r['_c'])) $res[]=ary2xml($r['_c'], $d+1);
// small hack ;)
elseif (isset($r['_v'])) $res[]="<![CDATA[".$r['_v']."]]>";
$res[]=(isset($r['_c']) ? $sp : '')."</$tag>\n";
}
}
return implode('', $res);
}
// Insert element into array
function ins2ary(&$ary, $element, $pos) {
$ar1=array_slice($ary, 0, $pos); $ar1[]=$element;
$ary=array_merge($ar1, array_slice($ary, $pos));
}
?>