Ignore:
Timestamp:
Nov 26, 2013, 11:16:15 PM (11 years ago)
Author:
chronos
Message:
  • Added: Identification code to language list.
  • Fixed: Locale update to database used fixed language id. Now id is detected from language code.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/Locale.php

    r609 r610  
    108108  }
    109109 
    110   function LoadFromDatabase($Database, $LanguageId)
     110  function LoadFromDatabase($Database, $LangCode)
    111111  {
    112         $this->Texts->Data = array();
    113         $DbResult = $Database->select('Locale', '`Original`, `Translated`', '`Language`='.$LanguageId * 1);
    114         while($DbRow = $DbResult->fetch_assoc())
    115           $this->Texts->Data[$DbRow['Original']] = $DbRow['Translated'];
     112        $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode));
     113        if($DbResult->num_rows > 0)
     114        {
     115          $Language = $DbResult->fetch_assoc();
     116        $this->Texts->Data = array();
     117        $DbResult = $Database->select('Locale', '`Original`, `Translated`', '`Language`='.$Language['Id']);
     118          while($DbRow = $DbResult->fetch_assoc())
     119            $this->Texts->Data[$DbRow['Original']] = $DbRow['Translated'];
     120        }
    116121  }
    117122
    118   function SaveToDatabase(Database $Database, $LanguageId)
     123  function SaveToDatabase(Database $Database, $LangCode)
    119124  {
    120         $Database->delete('Locale', '`Language`='.$LanguageId * 1);
    121         foreach($this->Texts->Data as $Index => $Item)
    122           $Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '.
    123           'VALUES('.$LanguageId.','.$Database->quote($Index).','.$Database->quote($Item).')');
     125        $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode));
     126        if($DbResult->num_rows > 0)
     127        {
     128          $Language = $DbResult->fetch_assoc();
     129          $Database->delete('Locale', '`Language`='.$Language['Id']);
     130          foreach($this->Texts->Data as $Index => $Item)
     131          $Database->query('INSERT INTO `Locale` (`Language`,`Original`,`Translated`) '.
     132            'VALUES('.$Language['Id'].','.$Database->quote($Index).','.$Database->quote($Item).')');
     133        }
    124134  }
    125135
    126   function UpdateToDatabase(Database $Database, $LanguageId)
     136  function UpdateToDatabase(Database $Database, $LangCode)
    127137  {
    128         foreach($this->Texts->Data as $Index => $Item)
    129     {
    130           $DbResult = $Database->select('Locale', '*', '`Original` ='.$Database->quote($Index));
    131           if($DbResult->num_rows > 0)
    132           $Database->update('Locale', '(`Language`='.($LanguageId * 1).') AND '.
    133         '(`Original` ='.$Database->quote($Index).')', array('Translated' => $Item));
    134           else $Database->insert('Locale', array('Language' => $LanguageId * 1,
    135        'Original' => $Index, 'Translated' => $Item));
    136     }
     138        $DbResult = $Database->select('Language', '*', 'Code='.$Database->quote($LangCode));
     139        if($DbResult->num_rows > 0)
     140        {
     141          $Language = $DbResult->fetch_assoc();
     142        foreach($this->Texts->Data as $Index => $Item)
     143      {
     144            $DbResult = $Database->select('Locale', '*', '(`Original` ='.$Database->quote($Index).') AND (`Language`='.($Language['Id']).')');
     145          if($DbResult->num_rows > 0)
     146          $Database->update('Locale', '(`Language`='.($Language['Id']).') AND '.
     147          '(`Original` ='.$Database->quote($Index).')', array('Translated' => $Item));
     148          else $Database->insert('Locale', array('Language' => $Language['Id'],
     149         'Original' => $Index, 'Translated' => $Item));
     150      }
     151        }
    137152  }
    138153}
Note: See TracChangeset for help on using the changeset viewer.