src/Framework/Routing/RouteGenerator/I18nRouteGenerator.php
protected function localizeCollection(array $prefixes, RouteCollection $collection)
    {
        $removeRoutes = array();
        $newRoutes = new RouteCollection();
        foreach ($collection->all() as $name => $route) {
            $routeLocale = $route->getDefault(self::LOCALE_PARAM);
            if ($routeLocale !== null) {
                if (!isset($prefixes[$routeLocale])) {
                    throw new MissingRouteLocaleException(sprintf('Route `%s`: No prefix found for locale "%s".', $name, $routeLocale));
                }
                $route->setPath('/' . $prefixes[$routeLocale] . $route->getPath());
                continue;
            }
            // No locale found for the route so localize the route
            $removeRoutes[] = $name;
            foreach ($prefixes as $locale => $prefix) {
                /** @var \Symfony\Component\Routing\Route $localeRoute */
                $localeRoute = clone $route;
                $localeRoute->setPath('/' . $prefix . $route->getPath());
                $localeRoute->setDefault(self::LOCALE_PARAM, $locale);
                $newRoutes->add(
                    $this->routeNameInflector->inflect($name, $locale),
                    $localeRoute
                );
            }
        }
        $collection->remove($removeRoutes);
        $collection->addCollection($newRoutes);
    }
protected function localizeCollection(array $prefixes, RouteCollection $collection)
    {
        $removeRoutes = array();
        $newRoutes = new RouteCollection();
        foreach ($collection->all() as $name => $route) {
            $routeLocale = $route->getDefault(self::LOCALE_PARAM);
            if ($routeLocale !== null) {
                if (!isset($prefixes[$routeLocale])) {
                    throw new MissingRouteLocaleException(sprintf('Route `%s`: No prefix found for locale "%s".', $name, $routeLocale));
                }
                $route->setPath('/' . $prefixes[$routeLocale] . $route->getPath());
                continue;
            }
            // No locale found for the route so localize the route
            $removeRoutes[] = $name;
            foreach ($prefixes as $locale => $prefix) {
                /** @var \Symfony\Component\Routing\Route $localeRoute */
                $localeRoute = clone $route;
                $localeRoute->setPath('/' . $prefix . $route->getPath());
                $localeRoute->setDefault(self::LOCALE_PARAM, $locale);
                $newRoutes->add(
                    $this->routeNameInflector->inflect($name, $locale),
                    $localeRoute
                );
            }
        }
        $collection->remove($removeRoutes);
        $collection->addCollection($newRoutes);
    }
protected function localizeCollection ( array $ prefixes , RouteCollection $ collection ) { $ removeRoutes = array ( ) ; $ newRoutes = new RouteCollection ( ) ; foreach ( $ collection -> all ( ) as $ name => $ route ) { $ routeLocale = $ route -> getDefault ( self :: LOCALE_PARAM ) ; if ( $ routeLocale !== null ) { if ( ! isset ( $ prefixes [ $ routeLocale ] ) ) { throw new MissingRouteLocaleException ( sprintf ( 'Route `%s`: No prefix found for locale "%s".' , $ name , $ routeLocale ) ) ; } $ route -> setPath ( '/' . $ prefixes [ $ routeLocale ] . $ route -> getPath ( ) ) ; continue ; } // No locale found for the route so localize the route $ removeRoutes [ ] = $ name ; foreach ( $ prefixes as $ locale => $ prefix ) { /** @var \Symfony\Component\Routing\Route $localeRoute */ $ localeRoute = clone $ route ; $ localeRoute -> setPath ( '/' . $ prefix . $ route -> getPath ( ) ) ; $ localeRoute -> setDefault ( self :: LOCALE_PARAM , $ locale ) ; $ newRoutes -> add ( $ this -> routeNameInflector -> inflect ( $ name , $ locale ) , $ localeRoute ) ; } } $ collection -> remove ( $ removeRoutes ) ; $ collection -> addCollection ( $ newRoutes ) ; }
Localize a route collection.

@param array $prefixes
@param RouteCollection $collection
Localize a route collection .