public function translate($key, $dictionaryName = 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->getFilename(), $this->tag->getLineNumber());
            }
            try {
                return $dictionary->translate($key);
            } catch (DictionaryEntryNotFoundException $ex) {
                $ex->setDictionaryName($dictionaryName);
                $ex->setTemplateFile($this->getFilename(), $this->tag->getLineNumber());
                throw $ex;
            }
        }

        //Walk the array of dictionaries, to try the lookup in all of them.
        foreach($this->dictionaries[count($this->dictionaries) - 1] 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.
            }
        }

        throw new DictionaryEntryNotFoundException($key, $this->getFilename(), $this->tag->getLineNumber());
    }