Example #1
0
 /**
  * @param string $name
  * @param array $parameters
  * @param bool|string $referenceType
  * @throws \UnexpectedValueException
  * @return string
  */
 public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
 {
     $originalParameters = $parameters;
     try {
         if (isset($parameters['_locale'])) {
             $locale = $parameters['_locale'];
         } else {
             $locale = $this->getContext()->getParameter('_locale');
         }
         if (!in_array($locale, $this->registry->getRegisteredLocales())) {
             throw new \UnexpectedValueException(sprintf('The locale %s has not been registered in the leapt_i18n config', $locale));
         }
         $i18nName = $name . '.' . $locale;
         unset($parameters['_locale']);
         return parent::generate($i18nName, $parameters, $referenceType);
     } catch (RouteNotFoundException $e) {
         return parent::generate($name, $originalParameters, $referenceType);
     }
 }
 /**
  * @param RouteCollection $collection
  * @param $annot
  * @param $globals
  * @param \ReflectionClass $class
  * @param \ReflectionMethod $method
  */
 protected function addRoute(RouteCollection $collection, $annot, $globals, \ReflectionClass $class, \ReflectionMethod $method)
 {
     $i18n = isset($annot->data['i18n']) ? $annot->data['i18n'] : true;
     unset($annot->data['i18n']);
     foreach ($this->registry->getRegisteredLocales() as $locale) {
         $i18nAnnot = new Route($annot->data);
         $i18nGlobals = $globals;
         if ($i18n) {
             $i18nAnnot->setName($this->helper->alterName($i18nAnnot->getName(), $locale));
             $i18nAnnot->setPath($this->helper->alterPath($i18nAnnot->getPath(), $locale));
             $i18nAnnot->setDefaults($this->helper->alterDefaults($i18nAnnot->getDefaults(), $locale));
             if (isset($i18nGlobals['path']) && !empty($i18nGlobals['path'])) {
                 $i18nGlobals['path'] = '/' . $locale . '/' . ltrim($this->helper->alterPath($i18nGlobals['path'], $locale), '/');
             } else {
                 $i18nGlobals['path'] = '/' . $locale;
             }
         }
         parent::addRoute($collection, $i18nAnnot, $i18nGlobals, $class, $method);
     }
 }
Example #3
0
 /**
  * @param string $locale
  * @param string $path
  */
 public function addSwitchPath($locale, $path)
 {
     $this->registry->addSwitchPath($locale, $path);
 }