[pmwiki-users] Page translation, translate only differences

Thomas Bley thbley at gmail.com
Wed Jul 19 13:25:11 CDT 2006


Hello,

translating pages is always a bit difficult: You translate the original 
page, then it changes and you only want to translate the differences.
I did some coding on this. The code may not be fully compatible and it 
may not serve all needs, but I think it gives good ideas for developing 
new features in this topic.

See the attached screenshot for the result:
- You see a German page named MainDe.About in the edit mode.
- At the right there is the Page History of the English version named 
"Main.About".
- The Page History only shows changes done after the last Translation 
(=the modification date of MainDe.About).
- If there are no new changes, all changes are shown.


My code changes:

config.php:
// set the template page used when creating a new page
$EditTemplatesFmt = 
preg_replace("/(.*?)[A-Z][a-z](\..*?)/","\\1\\2",$pagename);

// set the Page History to show only markup changes if page is in edit mode
if ($_REQUEST["action"]=="edit") $DiffShow['source'] = "y";


pmwiki.php / function HandleEdit()
replace:
  if (@$PageEditForm) {
    $form = ReadPage(FmtPageName($PageEditForm, $pagename), 
READPAGE_CURRENT);
    $FmtV['$EditForm'] = MarkupToHTML($pagename, $form['text']);
  }
with:
  if (@$PageEditForm) {
    $form = ReadPage(FmtPageName($PageEditForm, $pagename), 
READPAGE_CURRENT);
    $FmtV['$EditForm'] = MarkupToHTML($pagename, $form['text']);

    if (preg_match("/^.*?[A-Z][a-z]\./",$pagename)) { // page is a 
translated page e.g. MainDe.blabla
      global $EditTemplatesFmt, $WorkDir;
      if (PageExists($pagename) && PageExists($EditTemplatesFmt)) {
        ob_start();
        PrintDiff($EditTemplatesFmt,filemtime($WorkDir."/".$pagename));
        $diff = ob_get_contents();
        if ($diff=="") {
          PrintDiff($EditTemplatesFmt);
          $diff = ob_get_contents();
        }
        ob_end_clean();

        if ($diff!="") {
          $out = "<style>#wikiedit textarea { width:600px; } .diffbox { 
width:100%; }</style>"; // make wikiedit area and diffbox smaller
          $out .= "<table style='width:960px;'><tr><td valign='top'>";
          $out .= $FmtV['$EditForm'];
          $out .= "</td><td valign='top'>".$diff."</td></tr></table>";
          $FmtV['$EditForm'] = $out;
        }
      }
    }
  }

pagerev.php / PrintDiff()
replace:
function PrintDiff($pagename) {
with:
function PrintDiff($pagename,$begin=0) {

replace:
    if ($diffclass=='minor' && $DiffShow['minor']!='y') continue;
    $diffgmt = $match[1]; $FmtV['$DiffTime'] = strftime($TimeFmt,$diffgmt);
with:
    if ($diffclass=='minor' && $DiffShow['minor']!='y') continue;
    $diffgmt = $match[1]; $FmtV['$DiffTime'] = strftime($TimeFmt,$diffgmt);
    // only show changes newer than begin
    if ($begin!=0 && $diffgmt < $begin) continue;


stdconfig.php
replace:
if ($action=='diff' && @!$HandleActions['diff'])
  include_once("$FarmD/scripts/pagerev.php");

with:
if (($action=='edit' || $action=='diff') && @!$HandleActions['diff'])
  include_once("$FarmD/scripts/pagerev.php");


bye
Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: edit_diffs.png
Type: image/png
Size: 31578 bytes
Desc: not available
Url : /pipermail/pmwiki-users/attachments/20060719/2f04a67b/attachment.png 


More information about the pmwiki-users mailing list