Exemple #1
0
 /**
  * @return String
  */
 public function uri()
 {
     return new String(strUri($this->value));
 }
Exemple #2
0
 /**
  * @return string
  */
 public function uri()
 {
     return strUri($this->value);
 }
Exemple #3
0
 /**
  * Translates a text using current language and an optionnal given context
  *
  * @param $text    string
  * @param $context string
  * @return string
  */
 public function translate($text, $context = '')
 {
     if (!trim($text) || is_numeric($text)) {
         return $text;
     } elseif (strpos($text, DOT) !== false) {
         $translation = [];
         foreach (explode(DOT, $text) as $sentence) {
             $translation[] = $this->translate($sentence, $context);
         }
         return join(DOT, $translation);
     } elseif (!isset($this->cache[$text]) || !isset($this->cache[$text][$context])) {
         if (substr($text, -1) === AT) {
             $str_uri = true;
             $text = substr($text, 0, -1);
         } else {
             $str_uri = false;
         }
         $search = new Translation($text, $this->language, $context);
         $translations = Dao::search($search);
         foreach ($translations as $translation) {
             if ($translation->text === $text) {
                 break;
             }
         }
         while ($search->context && !isset($translation)) {
             $i = strrpos($search->context, DOT);
             $search->context = $i ? substr($search->context, 0, $i) : '';
             $translations = Dao::search($search);
             foreach ($translations as $translation) {
                 if ($translation->text === $text) {
                     break;
                 }
             }
         }
         if (!isset($translation) && strpos($text, ', ')) {
             $translation_parts = [];
             foreach (explode(', ', $text) as $text_part) {
                 $translation_parts[] = $this->translate($text_part, $context);
             }
             $translation = new Translation($text, $this->language, $context, join(', ', $translation_parts));
         }
         if (!isset($translation)) {
             $translation = $search;
             $translation->text = str_replace('_', SP, strtolower($translation->text));
             $translation->translation = '';
             Dao::write($translation);
         }
         $translation = $translation ? $translation->translation : $text;
         if ($str_uri) {
             $text .= AT;
             $translation = strUri($translation);
         }
         $this->cache[$text][$context] = $translation;
     }
     $translation = $this->cache[$text][$context];
     return empty($translation) ? $text : (strIsCapitals($text[0]) ? ucfirsta($translation) : $translation);
 }