/**
  * Translates the string in correct language
  * @param string $string The string to translate
  * @param array $paramList The param list to be replaced in the string
  * @param int $quantity The quantity to pluralize the string
  * @param string $category The translation's category
  * @return string The translated string
  */
 public function translate($string, $paramList = NULL, $quantity = NULL, $category = NULL)
 {
     // Checks if string has to be pluralized
     if ($quantity !== NULL && $quantity !== 1) {
         $string .= '_PLURAL';
     }
     // Set silent mode to avoid every translation log
     LogTool::getInstance()->setSilentMode();
     return $string;
     // Gets string from database
     try {
         if ($category !== NULL) {
             $category = ' AND translation_category = \'' . $category . '\'';
         } else {
             $category = '';
         }
         $translation = ElementFactory::getElement('Translation', NULL, 'translation_language = \'' . $this->getLocale() . '\' AND translation_text = \'' . $string . '\'' . $category);
         LogTool::getInstance()->unsetSilentMode();
         if ($paramList === NULL) {
             return $translation->value;
         }
         // String has params "%1" to be replaced
         if (!is_array($paramList)) {
             $paramList = array($paramList);
         }
         // Sets pattern to be replaced
         $patternList = array();
         for ($paramNumber = 1; $paramNumber <= count($paramList); ++$paramNumber) {
             $patternList[] = '/%' . $paramNumber . '(?![0-9])/';
         }
         return preg_replace($patternList, $paramList, $translation->value);
     } catch (ElementNoResultException $e) {
         // String is not localized
         try {
             $warningTracking = new WarningTracking();
             $warningTracking->addTracking("Missing " . $this->getLocale() . " translation on " . $string);
             // TODO : Get template.
             DatabaseFactory::commit();
         } catch (Exception $e) {
         }
         LogTool::getInstance()->unsetSilentMode();
         return 'TO_BE_LOCALIZED(' . $string . ')';
     }
 }
Пример #2
0
<?php

// ends transaction
DatabaseFactory::commit();