Changeset 393 for trunk


Ignore:
Timestamp:
Mar 17, 2010, 1:21:49 PM (15 years ago)
Author:
maron
Message:

Zvýrazňování názvů jmen a slov ze slovníčku u překladů

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/dictionary.php

    r379 r393  
    33include('includes/global.php');
    44
    5 function GetIDbyName($Table)
     5function WriteTranslatNames($Text,$mode)
    66{
    7   global $TranslationTree;
    8  
    9   foreach($TranslationTree as $TableID => $Value)
    10   {
    11     //echo $Value['TablePrefix'].'='.$Table.'<br>';
    12       if ($Value['TablePrefix'] == $Table) return $TableID;
    13   }
    14 }
    15 
    16 function GetTranslatNames($Text)
    17 {
    18   global $Database, $mode;
    19  
    20   if ($mode == 0) echo ('..Přesné');
     7       
     8  if ($mode == 0) echo ('..Nalezené názvy jmen věcí, míst, postav');
    219  if ($mode == 1) echo ('..Všechny přeložené');
    2210  if ($mode == 2) echo ('..Nepřeložené');
    23   echo('<div style="overflow: auto; width: 100%; height: 345px;"><table width="98%" class="BaseTable">');
    24   echo('<tr><th>Originál</th>'.'<th>Překlad</th>');
     11  echo('<table width="98%" class="BaseTable">');
     12  echo('<tr><th>Originál</th>'.'<th>Překlad</th></tr>');
     13
     14
    2515  $TablesColumn = array
    2616  (
     
    3121    'TextAreaTriggerTeleport' => 'Name',
    3222    'TextAreaTriggerTavern' => 'Name',
     23    'Dictionary' => 'Text',
    3324  );
    34  /* $TablesID = array('gameobject' => 5,
    35   'creature' => 6,
    36   'item' => 4,
    37   'transports' => 'Name',
    38   'areatrigger_teleport' => 'Name',
    39   'areatrigger_tavern' => 'Name',); */
     25
     26  $buff = GetTranslatNames($Text,$mode,$TablesColumn);
    4027 
    41   foreach($TablesColumn as $Table => $Column)
    42   { 
    43     $sql = 'SELECT `ID`,`'.$Column.'`, (SELECT `Name` FROM `'.$Table.'` AS `T` WHERE `O`.`Entry` = `T`.`Entry` AND `Language` <> 0 LIMIT 1) AS `Tran` FROM `'.$Table.'` AS `O` WHERE ';
    44     $groupby = ' GROUP BY `'.$Column.'`';
    45  
    46     $ArrStr = explode(' ', $Text);
    47     $where = '`Language` = 0 ';
    48     if ($mode == 1) $where .= ' AND EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> 0) AND (`Sub`.`Entry` = `O`.`Entry`))';
    49     if ($mode == 2) $where .= ' AND NOT EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> 0) AND (`Sub`.`Entry` = `O`.`Entry`))';
    50     $where .= ' AND (';
    51  
    52     for($i = 0; $i < count($ArrStr); $i++)
    53     {
    54       if (strpos($ArrStr[$i],'\'s') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-4);
    55       if (strpos($ArrStr[$i],',') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
    56       if (strpos($ArrStr[$i],'.') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
    57       if (strpos($ArrStr[$i],'!') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
    58       if (strpos($ArrStr[$i],'?') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
    59 
    60       if (strlen($ArrStr[$i]) > 4)
    61         $where .= '(`O`.`'.$Column.'` LIKE "%'.addslashes($ArrStr[$i]).'%") OR ';
    62     }
    63     $where = substr($where,0,strlen($where)-4);
    64     $where .= ')';
    65     echo('</tr>');
    66 
    67     $ID = $Database->SQLCommand($sql.$where.$groupby);
    68     while($Line = mysql_fetch_assoc($ID))
    69     {
     28         // $buff[] = array($Line['ID'],GetIDbyName($Table),$Line[$Column],$Line['Tran']);
     29  foreach($buff as $Line) {
    7030      if ($mode == 0)
    7131      {
    72         if (strpos(strtolower($Text), strtolower($Line[$Column])) > 0)
    73         {
    74           echo('<tr><td>'.$Line[$Column].'</td>');
    75           if ($Line['Tran'] <> '') echo('<td>'.$Line['Tran'].'</td></tr>');
    76           else echo('<td><a target="_NEW2" href="form.php?group='.GetIDbyName($Table).'&amp;ID='.$Line['ID'].'">Překládat</a></td></tr>');
     32        if (strpos(strtolower($Text), strtolower($Line[2])) > 0)
     33        {
     34          echo('<tr><td>'.$Line[2].'</td>');
     35          if ($Line[3] <> '') echo('<td><a target="_NEW2" href="form.php?group='.$Line[1].'&amp;ID='.$Line[0].'">'.$Line[3].'</a></td></tr>');
     36          else echo('<td><a target="_NEW2" href="form.php?group='.$Line[1].'&amp;ID='.$Line[0].'">Překládat</a></td></tr>');
    7737        }
    7838      } else
    7939      {
    80         echo('<tr><td>'.$Line[$Column].'</td>');
    81           if ($Line['Tran'] <> '') echo('<td>'.$Line['Tran'].'</td></tr>');
    82           else echo('<td><a target="_NEW2" href="form.php?group='.GetIDbyName($Table).'&amp;ID='.$Line['ID'].'">Překládat</a></td></tr>');
     40        echo('<tr><td>'.$Line[2].'</td>');
     41          if ($Line[3] <> '') echo('<td><a target="_NEW2" href="form.php?group='.$Line[1].'&amp;ID='.$Line[0].'">'.$Line[3].'</a></td></tr>');
     42          else echo('<td><a target="_NEW2" href="form.php?group='.$Line[1].'&amp;ID='.$Line[0].'">Překládat</a></td></tr>');
    8343      }
    84     }
    85   }
    86   echo('</table></div>');
     44  }
     45
     46  echo('</table>');
    8747}
    8848
     
    11979    foreach($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
    12080      $Text .= ' '.$Line[$TextItem['Column']];
    121         GetTranslatNames($Text);
     81        WriteTranslatNames($Text,$mode);
    12282  }
    12383} else
  • trunk/form.php

    r376 r393  
    22
    33include('includes/global.php');   
     4
     5function ColorNames($Text,$names) {
     6       
     7         // $buff[] = array($Line['ID'],GetIDbyName($Table),$Line[$Column],$Line['Tran']);
     8  foreach($names as $Line) {
     9         if ($Line[3] <> '') {
     10           $Text = str_replace($Line[2],'<span Title="Byl nalezen překlad: '.$Line[3].'" class="edit">'.$Line[2].'</span>',$Text);
     11           $Text = str_replace(strtolower($Line[2]),'<span Title="Byl nalezen překlad: '.$Line[3].'" class="edit">'.$Line[2].'</span>',$Text);
     12         } else {
     13       $Text = str_replace($Line[2],'<span Title="Jméno bylo nalezeno v názvech a můžete ho přeložit. Začnete kliknutím na: Vyhledat v názvech" class="edit">'.$Line[2].'</span>',$Text);
     14       $Text = str_replace(strtolower($Line[2]),'<span Title="Jméno bylo nalezeno v názvech a můžete ho přeložit. Začnete kliknutím na: Vyhledat v názvech" class="edit">'.$Line[2].'</span>',$Text);
     15     }
     16  }
     17        return $Text;
     18}
    419
    520ShowPage();
     
    110125  WriteLanguages($Language);
    111126  echo('</td></tr>');
     127
     128  //zvýrazňování jmen
     129    $Text = '';
     130    foreach($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
     131      if($TextItem['Visible'] == 1)
     132        $Text = $Text.' '.$LineAJ[$TextItem['Column']];
     133
     134  if(($GroupId < 4) or ($GroupId == 10) or ($GroupId == 11)) {
     135  //<span class="edit">barvou.</span>
     136    $names = GetTranslatNames($Text,0,array('Dictionary' => 'Text','TextCreature' => 'name'));
     137  } else {
     138    $names = GetTranslatNames($Text,0,array('Dictionary' => 'Text'));
     139  }
     140  //print_r($names);
     141
    112142  foreach($TranslationTree[$GroupId]['Items'] as $Index => $TextItem)
    113143  if($TextItem['Visible'] == 1)
     
    117147      if ($TextItem['Name'] == 'Text' AND (($Table == 'global_strings') OR ($Table == 'glue_strings'))) echo('<tr><th>'.$LineAJ['ShortCut'].'</th>');
    118148        else echo('<tr><th>'.$TextItem['Name'].'</th>');
    119       echo('<td>'.str_replace("\n", '<br/>', htmlspecialchars($LineAJ[$TextItem['Column']])).'</td>
     149      echo('<td>'.str_replace("\n", '<br/>', ColorNames(htmlspecialchars($LineAJ[$TextItem['Column']]),$names)).'</td>
    120150      <td><textarea rows="8" cols="40" onkeydown="ResizeTextArea(this)" class="textedit" id="'.$TextItem['Column'].'" name="'.$TextItem['Column'].'">'.htmlspecialchars($Line[$TextItem['Column']]).'</textarea></td></tr>');
    121151    }
  • trunk/includes/global_function.php

    r382 r393  
    462462}
    463463
     464function GetIDbyName($Table)
     465{
     466  global $TranslationTree;
     467 
     468  foreach($TranslationTree as $TableID => $Value)
     469  {
     470    //echo $Value['TablePrefix'].'='.$Table.'<br>';
     471      if ($Value['TablePrefix'] == $Table) return $TableID;
     472  }
     473}
     474
     475
     476function GetTranslatNames($Text,$mode,$TablesColumn)
     477{
     478  global $Database;
     479 
     480 /* $TablesID = array('gameobject' => 5,
     481  'creature' => 6,
     482  'item' => 4,
     483  'transports' => 'Name',
     484  'areatrigger_teleport' => 'Name',
     485  'areatrigger_tavern' => 'Name',); */
     486    $buff = array();
     487 
     488  foreach($TablesColumn as $Table => $Column)
     489  { 
     490    $sql = 'SELECT `ID`,`'.$Column.'`, (SELECT `'.$Column.'` FROM `'.$Table.'` AS `T` WHERE `O`.`Entry` = `T`.`Entry` AND `Language` <> 0 LIMIT 1) AS `Tran` FROM `'.$Table.'` AS `O` WHERE ';
     491    $groupby = ' GROUP BY `'.$Column.'`';
     492 
     493    $ArrStr = explode(' ', $Text);
     494    $where = '`Language` = 0 ';
     495    if ($mode == 1) $where .= ' AND EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> 0) AND (`Sub`.`Entry` = `O`.`Entry`))';
     496    if ($mode == 2) $where .= ' AND NOT EXISTS(SELECT 1 FROM `'.$Table.'` AS `Sub` WHERE (`Sub`.`Language` <> 0) AND (`Sub`.`Entry` = `O`.`Entry`))';
     497    $where .= ' AND (';
     498 
     499    for($i = 0; $i < count($ArrStr); $i++)
     500    {
     501      if (strpos($ArrStr[$i],"'s") > 0)
     502                   $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-2);
     503      if (strpos($ArrStr[$i],',') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
     504      if (strpos($ArrStr[$i],'.') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
     505      if (strpos($ArrStr[$i],'!') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
     506      if (strpos($ArrStr[$i],'?') > 0) $ArrStr[$i] = substr($ArrStr[$i],0,strlen($ArrStr[$i])-1);
     507
     508      if (strlen($ArrStr[$i]) > 5)
     509        $where .= '(`O`.`'.$Column.'` LIKE "%'.addslashes($ArrStr[$i]).'%") OR ';
     510    }
     511    $where = substr($where,0,strlen($where)-4);
     512    $where .= ')';
     513
     514    $ID = $Database->SQLCommand($sql.$where.$groupby);
     515    //echo ($sql.$where.$groupby);
     516    while($Line = mysql_fetch_assoc($ID))
     517    {
     518   //   if (($mode != 0) or (($mode == 0) and (strpos(strtolower($Text), strtolower($Line[2])) > 0) ) )
     519          $buff[] = array($Line['ID'],GetIDbyName($Table),$Line[$Column],$Line['Tran']);
     520    }
     521  }
     522    return $buff;
     523}
    464524?>
Note: See TracChangeset for help on using the changeset viewer.