Ejemplo n.º 1
0
 /**
  * Return translation. Select language or default based on getTxtId(). 
  * If Text is not translated return untranslated(). If text has changed
  * remove translation in database. Text $txt must be static otherwise use tok_ptxt(). 
  * Examples:
  *
  * - {txt:}Hallo {get:firstname} {get:lastname}{:txt} -> invalid !!
  * - {txt:}Hallo{:txt} -> id = md5('Hallo')
  * - {txt:hi}Hallo{:txt} -> id = hi
  * - {txt:}=hi{:txt} -> id = hi 
  *
  * @throws
  * @see getTxtId
  * @see untranslated
  * @see tok_ptxt
  * @param string $param custom id or empty
  * @param string $txt default text or empty
  * @return string
  */
 public function tok_txt($param, $txt)
 {
     $id = $this->getTxtId($param, $txt);
     if (($trans = $this->db->query('select', ['id' => $id], -1)) === false) {
         // no translation - insert untranslated text and return raw
         $this->db->query('insert:exec', ['id' => $id, 'txt' => $txt]);
         return $this->untranslated('txt', $param, $txt);
     }
     if ($trans['txt'] !== $txt) {
         // text has changed: remove translation, insert untranslated text and return raw
         $this->db->query('delete:exec', ['id' => $id]);
         $this->db->query('insert:exec', ['id' => $id, 'txt' => $txt]);
         return $this->untranslated('txt', $param, $txt);
     }
     $res = $trans['lang'];
     if (empty($res)) {
         $res = empty($trans['default']) ? $this->untranslated('txt', $param, $txt) : $trans['default'];
     }
     return $res;
 }