Beispiel #1
0
 /**
  * Used to translate a text string into the language preference of the user.
  * @author Pascal Peyremorte (p.peyremorte@wanadoo.fr)
  * @global db_driver $zdbh The ZPX database handle.
  * @param $message The string to translate.
  * @return string The transalated string.
  */
 static function translate($message)
 {
     global $zdbh;
     if (empty(self::$LangCol)) {
         $uid = ctrl_auth::CurrentUserID();
         $sql = $zdbh->prepare('SELECT ud_language_vc FROM x_profiles WHERE ud_user_fk=' . $uid);
         $sql->execute();
         $lang = $sql->fetch();
         self::$LangCol = 'tr_' . $lang['ud_language_vc'] . '_tx';
     }
     if (self::$LangCol == 'tr_en_tx') {
         return $message;
     }
     //no translation required, english used
     $SlashedMessage = addslashes($message);
     //protect special chars
     $sql = $zdbh->prepare('SELECT ' . self::$LangCol . ' FROM x_translations WHERE tr_en_tx =:message');
     $sql->bindParam(':message', $SlashedMessage);
     $sql->execute();
     $result = $sql->fetch();
     if ($result) {
         if (!fs_director::CheckForEmptyValue($result[self::$LangCol])) {
             return $result[self::$LangCol];
         } else {
             return $message;
         }
         //translated message empty
     } else {
         //message not found in the table
         //add unfound message to the table with empties translations
         $sql = $zdbh->prepare('INSERT INTO x_translations SET tr_en_tx=:message');
         $sql->bindParam(':message', $SlashedMessage);
         $sql->execute();
         return $message;
     }
 }