Ignore:
Timestamp:
Apr 7, 2020, 11:53:58 AM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code formatting.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Locale.php

    r69 r92  
    2020  function Translate($Text, $Group = '')
    2121  {
    22     if(array_key_exists($Text, $this->Data[$Group]) and ($this->Data[$Group][$Text] != ''))
    23       return($this->Data[$Group][$Text]);
    24       else return($Text);
     22    if (array_key_exists($Text, $this->Data[$Group]) and ($this->Data[$Group][$Text] != ''))
     23      return $this->Data[$Group][$Text];
     24      else return $Text;
    2525  }
    2626
     
    2828  {
    2929    $Key = array_search($Text, $this->Data[$Group]);
    30     if(($Key === FALSE) or ($this->Data[$Group][$Key] == '')) return($Text);
    31       else return($Key);
     30    if (($Key === FALSE) or ($this->Data[$Group][$Key] == '')) return $Text;
     31      else return $Key;
    3232  }
    3333}
     
    4747  {
    4848    $FileName = $this->Dir.'/'.$Language.'.php';
    49     if(file_exists($FileName)) {
     49    if (file_exists($FileName)) {
    5050      include_once($FileName);
    5151      $ClassName = 'LocaleText'.$Language;
     
    5959    // Search for php files
    6060    $FileList = scandir($Path);
    61     foreach($FileList as $FileName)
     61    foreach ($FileList as $FileName)
    6262    {
    6363      $FullName = $Path.'/'.$FileName;
    64       if(($FileName == '.') or ($FileName == '..')) ; // Skip virtual items
    65       else if(substr($FileName, 0, 1) == '.') ; // Skip Linux hidden files
    66       else if(is_dir($FullName)) $this->AnalyzeCode($FullName);
    67       else if(file_exists($FullName))
    68       {
    69         if(substr($FullName, -4) == '.php')
     64      if (($FileName == '.') or ($FileName == '..')) ; // Skip virtual items
     65      else if (substr($FileName, 0, 1) == '.') ; // Skip Linux hidden files
     66      else if (is_dir($FullName)) $this->AnalyzeCode($FullName);
     67      else if (file_exists($FullName))
     68      {
     69        if (substr($FullName, -4) == '.php')
    7070        {
    7171          $Content = file_get_contents($FullName);
    7272          // Search occurence of T() function
    73           while(strpos($Content, 'T(') !== false)
     73          while (strpos($Content, 'T(') !== false)
    7474          {
    7575            $Previous = strtolower(substr($Content, strpos($Content, 'T(') - 1, 1));
     
    7777            $Ord = ord($Previous);
    7878            //echo($Ord.',');
    79             if(!(($Ord >= ord('a')) and ($Ord <= ord('z'))))
     79            if (!(($Ord >= ord('a')) and ($Ord <= ord('z'))))
    8080            {
    8181              // Do for non-alpha previous character
    8282              $Original = substr($Content, 0, strpos($Content, ')'));
    8383              $Original2 = '';
    84               if((substr($Original, 0, 1) == "'") and (substr($Original, -1, 1) == "'"))
     84              if ((substr($Original, 0, 1) == "'") and (substr($Original, -1, 1) == "'"))
    8585                $Original2 = substr($Original, 1, -1);
    86               if((substr($Original, 0, 1) == '"') and (substr($Original, -1, 1) == '"'))
     86              if ((substr($Original, 0, 1) == '"') and (substr($Original, -1, 1) == '"'))
    8787                $Original2 = substr($Original, 1, -1);
    88               if($Original2 != '')
     88              if ($Original2 != '')
    8989              {
    90                 if(!array_key_exists($Original2, $this->Texts->Data))
     90                if (!array_key_exists($Original2, $this->Texts->Data))
    9191                  $this->Texts->Data[$Original2] = '';
    9292              }
     
    109109    '    $this->Title = \''.$this->Texts->Title.'\';'."\n".
    110110    '    $this->Data = array('."\n";
    111     foreach($this->Texts->Data as $Index => $Item)
     111    foreach ($this->Texts->Data as $Index => $Item)
    112112    {
    113113      $Content .= "      '".$Index."' => '".$Item."',\n";
     
    122122  {
    123123    $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode));
    124     if($DbResult->num_rows > 0)
     124    if ($DbResult->num_rows > 0)
    125125    {
    126126      $Language = $DbResult->fetch_assoc();
    127127      $this->Texts->Data = array();
    128128      $DbResult = $Database->select('Locale', '`Original`, `Translated`', '`Language`='.$Language['Id']);
    129       while($DbRow = $DbResult->fetch_assoc())
     129      while ($DbRow = $DbResult->fetch_assoc())
    130130        $this->Texts->Data[$DbRow['Original']] = $DbRow['Translated'];
    131131    }
     
    135135  {
    136136    $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode));
    137     if($DbResult->num_rows > 0)
     137    if ($DbResult->num_rows > 0)
    138138    {
    139139      $Language = $DbResult->fetch_assoc();
    140140      $Database->delete('Locale', '`Language`='.$Language['Id']);
    141       foreach($this->Texts->Data as $Index => $Item)
     141      foreach ($this->Texts->Data as $Index => $Item)
    142142        $Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '.
    143143        'VALUES('.$Language['Id'].','.$Database->quote($Index).','.$Database->quote($Item).')');
     
    148148  {
    149149    $DbResult = $Database->select('Language', '*', '`Code`='.$Database->quote($LangCode));
    150     if($DbResult->num_rows > 0)
     150    if ($DbResult->num_rows > 0)
    151151    {
    152152      $Language = $DbResult->fetch_assoc();
    153       foreach($this->Texts->Data as $Index => $Item)
     153      foreach ($this->Texts->Data as $Index => $Item)
    154154      {
    155155        $DbResult = $Database->select('Locale', '*', '(`Original` ='.$Database->quote($Index).
    156156          ') AND (`Language`='.($Language['Id']).')');
    157         if($DbResult->num_rows > 0)
     157        if ($DbResult->num_rows > 0)
    158158        $Database->update('Locale', '(`Language`='.($Language['Id']).') AND '.
    159159          '(`Original` ='.$Database->quote($Index).')', array('Translated' => $Item));
     
    188188    $this->Available = array();
    189189    $FileList = scandir($this->Dir);
    190     foreach($FileList as $FileName)
    191     {
    192       if(substr($FileName, -4) == '.php')
     190    foreach ($FileList as $FileName)
     191    {
     192      if (substr($FileName, -4) == '.php')
    193193      {
    194194        $Code = substr($FileName, 0, -4);
     
    206206    $Locale->AnalyzeCode($Directory);
    207207    $FileList = scandir($this->Dir);
    208     foreach($FileList as $FileName)
    209     {
    210       if(substr($FileName, -4) == '.php')
     208    foreach ($FileList as $FileName)
     209    {
     210      if (substr($FileName, -4) == '.php')
    211211      {
    212212        $FileLocale = new LocaleFile($this->System);
     
    215215
    216216        // Add new
    217         foreach($Locale->Texts->Data as $Index => $Item)
    218           if(!array_key_exists($Index, $FileLocale->Texts->Data))
     217        foreach ($Locale->Texts->Data as $Index => $Item)
     218          if (!array_key_exists($Index, $FileLocale->Texts->Data))
    219219            $FileLocale->Texts->Data[$Index] = $Item;
    220220        // Remove old
    221         foreach($FileLocale->Texts->Data as $Index => $Item)
    222           if(!array_key_exists($Index, $Locale->Texts->Data))
     221        foreach ($FileLocale->Texts->Data as $Index => $Item)
     222          if (!array_key_exists($Index, $Locale->Texts->Data))
    223223            unset($FileLocale->Texts->Data[$Index]);
    224224        $FileLocale->UpdateToDatabase($this->System->Database, $FileLocale->Texts->Code);
     
    232232  function LoadLocale($Code)
    233233  {
    234     if(array_key_exists($Code, $this->Available))
     234    if (array_key_exists($Code, $this->Available))
    235235    {
    236236      $this->CurrentLocale->Dir = $this->Dir;
     
    245245  global $GlobalLocaleManager;
    246246
    247   if(isset($GlobalLocaleManager)) return($GlobalLocaleManager->CurrentLocale->Texts->Translate($Text, $Group));
    248     else return($Text);
    249 }
     247  if (isset($GlobalLocaleManager)) return $GlobalLocaleManager->CurrentLocale->Texts->Translate($Text, $Group);
     248    else return $Text;
     249}
Note: See TracChangeset for help on using the changeset viewer.