コード例 #1
0
ファイル: File.php プロジェクト: tboloo/figdice
 /**
  * If a dictionary name is specified, performs the lookup only in this one.
  * If the dictionary name is not in the perimeter of the current file,
  * bubbles up the translation request if a parent file exists.
  * Finally throws DictionaryNotFoundException if the dictionary name is not
  * found anywhere in the hierarchy.
  * 
  * If the entry is not found in the current file's named dictionary,
  * throws DictionaryEntryNotFoundException.
  * 
  * If no dictionary name parameter is specified, performs the lookup in every dictionary attached
  * to the current FIG file, and only if not found in any, bubbles up the request.
  * 
  * @param $key
  * @param string $dictionaryName
  * @return string
  * @throws DictionaryEntryNotFoundException
  * @throws DictionaryNotFoundException
  */
 public function translate($key, $dictionaryName = null, $xmlLineNumber = null)
 {
     //If a dictionary name is specified,
     if (null !== $dictionaryName) {
         // Use the nearest dictionary by this name,
         // in current file upwards.
         $dictionary = $this->getDictionary($dictionaryName);
         if (null == $dictionary) {
             throw new DictionaryNotFoundException($dictionaryName, $this, $xmlLineNumber);
         }
         try {
             return $dictionary->translate($key);
         } catch (DictionaryEntryNotFoundException $ex) {
             $ex->setDictionaryName($dictionaryName);
             $ex->setTemplateFile($this->filename, $xmlLineNumber);
             throw $ex;
         }
     }
     //Walk the array of dictionaries, to try the lookup in all of them.
     if (count($this->dictionaries)) {
         foreach ($this->dictionaries as $dictionary) {
             try {
                 return $dictionary->translate($key);
             } catch (DictionaryEntryNotFoundException $ex) {
                 // It is perfectly legitimate to not find a key in the first few registered dictionaries.
                 // But if in the end, we still didn't find a translation, it will be time to
                 // throw the exception.
             }
         }
     }
     if (null == $this->parentFile) {
         throw new DictionaryEntryNotFoundException($key, $this->filename, $xmlLineNumber);
     }
     return $this->parentFile->translate($key, $dictionaryName);
 }
コード例 #2
0
ファイル: File.php プロジェクト: jfrancr/figdice
 /**
  * If a dictionary name is specified, performs the lookup only in this one.
  * If the dictionary name is not in the perimeter of the current file,
  * bubbles up the translation request if a parent file exists.
  * Finally throws DictionaryNotFoundException if the dictionary name is not
  * found anywhere in the hierarchy.
  * 
  * If the entry is not found in the current file's named dictionary,
  * throws DictionaryEntryNotFoundException.
  * 
  * If no dictionary name parameter is specified, performs the lookup in every dictionary attached
  * to the current FIG file, and only if not found in any, bubbles up the request.
  * 
  * @param $key
  * @param string $dictionaryName
  * @return string
  * @throws DictionaryEntryNotFoundException, DictionaryNotFoundException
  */
 public function translate($key, $dictionaryName = null, $xmlLineNumber = null)
 {
     //If a dictionary name is specified,
     if (null !== $dictionaryName) {
         // Use the nearest dictionary by this name,
         // in current file upwards.
         $dictionary = $this->getDictionary($dictionaryName);
         if (null == $dictionary) {
             throw new DictionaryNotFoundException($dictionaryName);
         }
         try {
             return $dictionary->translate($key);
         } catch (DictionaryEntryNotFoundException $ex) {
             $ex->setDictionaryName($dictionaryName);
             $ex->setTemplateFile($this->filename, $xmlLineNumber);
             throw $ex;
         }
     }
     //Walk the array of dictionaries, to try the lookup in all of them.
     if (count($this->dictionaries)) {
         foreach ($this->dictionaries as $dictionary) {
             try {
                 return $dictionary->translate($key);
             } catch (DictionaryEntryNotFoundException $ex) {
             }
         }
     }
     if (null == $this->parentFile) {
         throw new DictionaryEntryNotFoundException($key);
     }
     return $this->parentFile->translate($key, $dictionaryName);
 }