Kayako logo
Modifications & Addon Releases Modification guides and addons are posted here to share with the community. Do not post requests in here!

Notices

Reply
 
LinkBack (2) Thread Tools Search this Thread Rate Thread Display Modes
  2 links from elsewhere to this Post. Click to view. (#1) Old
xUx Offline
New Member
 
Posts: 16
Join Date: Mar 2007
Location: Internet
Lightbulb Language File Compare Script (SupportSuite) - 26-03-2007, 03:33 AM

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($parserXML_OPTION_CASE_FOLDING0);
    
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($ary0$pos); $ar1[]=$element;
    
$ary=array_merge($ar1array_slice($ary$pos));
}

?>

Last edited by xUx; 06-04-2007 at 07:12 PM. Reason: Small bug fixed, works great now / Pequeño error corregido, funciona a la perfección :)
   
Reply With Quote
  (#2) Old
mblendinger Offline
Member
 
mblendinger's Avatar
 
Posts: 109
Join Date: Jan 2006
Location: Argentina
26-03-2007, 03:52 AM

Awesome tool, dude, Thank you very much!
   
Reply With Quote
  (#3) Old
xUx Offline
New Member
 
Posts: 16
Join Date: Mar 2007
Location: Internet
26-03-2007, 07:14 PM

You are welcome

Do you have a good translation file you would like to share in Spanish Language Pack for V3 ?

I'm looking for some spare time to post mine using SupportSuite 3.0.4.10 and share it to the community.
   
Reply With Quote
  (#4) Old
mblendinger Offline
Member
 
mblendinger's Avatar
 
Posts: 109
Join Date: Jan 2006
Location: Argentina
26-03-2007, 07:17 PM

I have the common one available from the forums for esupport since 3.0

But we will be upgrading to the lastest stable of eSupport and then we will be more than happy to share it with the community.
   
Reply With Quote
  (#5) Old
webmidas Offline
New Member
 
Posts: 4
Join Date: Sep 2007
03-10-2007, 09:00 AM

Great piece of code.
Will it compare english and spanish version only or it compares every language file.
BTW: where can we get a complete listing of all the laguages currently supported by esupport.I am thinking of making translation files for esupport, is there any type of permission required to make translation.


Live life to the fullest and love everybody
Host your site with web hosting india company
   
Reply With Quote
  (#6) Old
jetmuzer Offline
New Member
 
Posts: 1
Join Date: Nov 2007
26-11-2007, 08:54 PM

Hey!
I searched something like that. I hope that's it
Thanks for the code!
   
Reply With Quote
  (#7) Old
pabloaugusto Offline
Member
 
pabloaugusto's Avatar
 
Posts: 40
Join Date: Oct 2007
Location: Rio de Janeiro - Brasil
04-05-2008, 07:28 AM

We need a script like this to admin language, can you do this script friend?


Tudo sobre o Kayako em português do Brasil (pt-BR). Suporte a empresas e profissionais. Instalação, configuração, upgrade, traducao, temas, mail pipe e mail parse, traducao do front end, admin e staff (pt-br). Visite meu fórum de ajuda ao kayako em Português e para mais informações, entre em contato: email@pabloaugusto.com


   
Reply With Quote
  (#8) Old
craigbrass Offline
Senior Member
 
Posts: 5,762
Join Date: Jun 2005
Location: Cumbria, UK
04-05-2008, 07:43 AM

Try using WinMerge (WinMerge) - it works just as well.


Craig Brass - Kayako Forum Squatter (Note: I am NOT a staff member)

Icon Headquarters - Its Elixir - Web2Messenger
   
Reply With Quote
  (#9) Old
pabloaugusto Offline
Member
 
pabloaugusto's Avatar
 
Posts: 40
Join Date: Oct 2007
Location: Rio de Janeiro - Brasil
04-05-2008, 07:46 AM

Not the same thing,
dont works well with diferent languages =/


Tudo sobre o Kayako em português do Brasil (pt-BR). Suporte a empresas e profissionais. Instalação, configuração, upgrade, traducao, temas, mail pipe e mail parse, traducao do front end, admin e staff (pt-br). Visite meu fórum de ajuda ao kayako em Português e para mais informações, entre em contato: email@pabloaugusto.com


   
Reply With Quote
  (#10) Old
craigbrass Offline
Senior Member
 
Posts: 5,762
Join Date: Jun 2005
Location: Cumbria, UK
04-05-2008, 08:40 AM

It can easily tell you which lines have been added between versions though.


Craig Brass - Kayako Forum Squatter (Note: I am NOT a staff member)

Icon Headquarters - Its Elixir - Web2Messenger
   
Reply With Quote
Reply

Tags
compare, language, script, supportsuite

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://forums.kayako.com/f52/language-file-compare-script-supportsuite-11269/
Posted By For Type Date
PHP code to compare XML like ExamXML XML differencing tool This thread Refback 29-05-2008 10:24 PM
PHP code to compare XML files like ExamXML XML differencing tool This thread Refback 19-02-2008 06:23 PM



Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47