Beispiel #1
0
 /**
  * @param  string $value
  * @return boolean
  */
 public function validate($value)
 {
     if (true == $this->content) {
         $key = reset(explode("_", Locale::getKey()));
     } else {
         $key = $this->content;
     }
     if (true == array_key_exists($key, $this->patterns)) {
         return (bool) @preg_match($this->patterns[$key], $value);
     }
     return true;
 }
Beispiel #2
0
 /**
  * Renders a exception/error template
  *
  * @param array $args
  */
 protected static final function renderException($args)
 {
     Buffer::clear(true);
     /**
      * Set header status code
      */
     Header::set(500, false);
     /**
      * Reset all to the default
      */
     $activeProject = ProjectManager::getActiveProject();
     if ($activeProject) {
         $activeProject->setActive(false);
     }
     Locale::set(DEFAULT_LOCALE);
     /**
      * Render with the exception layout
      */
     self::renderTemplate(EXCEPTION_LAYOUT, $args, true);
     exit;
 }
Beispiel #3
0
 /**
  * Returns the current locale
  * key from the locale component
  *
  * @return string
  */
 public function getLocaleKey()
 {
     return Locale::getKey();
 }
Beispiel #4
0
 /**
  * Simply sets the default locale
  */
 protected final function initDefaultLocale()
 {
     Locale::set(DEFAULT_LOCALE);
 }
Beispiel #5
0
 /**
  * Returns a translation string
  *
  * @param  string $value
  * @return string
  */
 public static function execLANG($value)
 {
     $translation = Locale::get($value);
     return !is_array($translation) ? $translation : '';
 }
Beispiel #6
0
 /**
  * Get a translation from a file by a path
  *
  * @param  string|arary $path
  * @return string
  */
 public static function get($path)
 {
     $project = ProjectManager::getActiveProject();
     $project = $project ? $project : ProjectManager::getDefaultProject();
     $pathParts = ArrayHelper::clean(explode(self::SUBPATH_SEPERATOR, $path));
     $localeDir = PathHelper::createPath(array($project->getTranslationPath(), Locale::getKey()));
     $entryPoint = '';
     $entryPointIndex = 0;
     // Check if path is empty
     if (empty($pathParts)) {
         return '';
     }
     // Get entry point file
     for ($i = 0, $len = count($pathParts); $i < $len; $i++) {
         $isFile = false;
         $localeDir = PathHelper::getRealPath($localeDir);
         for ($x = 0, $lenX = count(self::$translationTypes); $x < $lenX; $x++) {
             $fileExt = self::$translationTypes[$x];
             $pathPart = $pathParts[$i];
             $isFile = is_file($localeDir . $pathPart . '.' . $fileExt);
             // Escape loop if file was found
             if (true == $isFile) {
                 break;
             }
         }
         // Attach current "dir" to the localdir (next level)
         $localeDir .= $pathPart;
         // Excape loop if entry point was found
         if (true == $isFile) {
             $entryPointIndex = $i;
             $entryPoint = $localeDir . '.' . $fileExt;
             break;
         }
     }
     /**
      * If there is no entry point take
      * all supported translation files
      * from the given directory
      */
     if (empty($entryPoint) && is_dir($localeDir)) {
         $files = DirHelper::scanDir($localeDir);
         $names = array();
         foreach ($files as $file) {
             $extension = pathinfo($file['path'], PATHINFO_EXTENSION);
             $filename = pathinfo($file['path'], PATHINFO_FILENAME);
             if (array_search($extension, self::$translationTypes) !== false) {
                 $names[] = $filename;
             }
         }
         return $names;
     }
     // if (true == empty($entryPoint)) {
     //     throw new Translator\Exception\EntryPointNotFoundException("No entry point (file) found for: " . (string) $path);
     // }
     $pathParts = array_slice($pathParts, $entryPointIndex + 1);
     $pathParts = ArrayHelper::clean($pathParts);
     // The default translation value
     $value = $path;
     /**
      * Operate with the key functions for different file types.
      * At this point we are handling valid values
      */
     switch ($fileExt) {
         case self::$translationTypes[0]:
             $value = self::getValueByKeyPHP($entryPoint, $pathParts);
             break;
         case self::$translationTypes[1]:
             $value = self::getValueByKeyCSV($entryPoint, $pathParts);
             break;
     }
     /**
      * If the value is a array and empty it doesn't
      * need to be returned. Return a empty string
      * instead
      */
     if (empty($value)) {
         return '';
     } else {
         return $value;
     }
 }