library/Garp/I18n.php
public static function getLocalizedRoutes(array $routes, array $locales) {
        $localizedRoutes = array();
        $defaultLocale = self::getDefaultLocale();
        $requiredLocalesRegex = '^(' . join('|', $locales) . ')$';

        foreach ($routes as $key => $value) {
            // First let's add the default locale to this routes defaults.
            $defaults = isset($value['defaults'])
                ? $value['defaults']
                : array();

            // Always default all routes to the Zend_Locale default
            $value['defaults'] = array_merge(array('locale' => $defaultLocale ), $defaults);

            //$routes[$key] = $value;

            // Get our route and make sure to remove the first forward slash
            // since it's not needed.
            $routeString = $value['route'];
            $routeString = ltrim($routeString, '/\\');

            // Modify our normal route to have the locale parameter.
            if (!isset($value['type']) || $value['type'] === 'Zend_Controller_Router_Route') {
                $value['route'] = ':locale/' . $routeString;
                $value['reqs']['locale'] = $requiredLocalesRegex;
                $localizedRoutes['locale_' . $key] = $value;
            } else if ($value['type'] === 'Zend_Controller_Router_Route_Regex') {
                $value['route'] = '(' . join('|', $locales) . ')\/' . $routeString;

                // Since we added the local regex match, we need to bump the existing
                // match numbers plus one.
                $map = isset($value['map']) ? $value['map'] : array();
                foreach ($map as $index => $word) {
                    unset($map[$index++]);
                    $map[$index] = $word;
                }

                // Add our locale map
                $map[1] = 'locale';
                ksort($map);

                $value['map'] = $map;

                $localizedRoutes['locale_' . $key] = $value;
            } elseif ($value['type'] === 'Zend_Controller_Router_Route_Static') {
                foreach ($locales as $locale) {
                    $value['route'] = $locale . '/' . $routeString;
                    $value['defaults']['locale'] = $locale;
                    $routes['locale_' . $locale . '_' . $key] = $value;
                }
            }
        }
        return $localizedRoutes;
    }
public static function getLocalizedRoutes(array $routes, array $locales) {
        $localizedRoutes = array();
        $defaultLocale = self::getDefaultLocale();
        $requiredLocalesRegex = '^(' . join('|', $locales) . ')$';

        foreach ($routes as $key => $value) {
            // First let's add the default locale to this routes defaults.
            $defaults = isset($value['defaults'])
                ? $value['defaults']
                : array();

            // Always default all routes to the Zend_Locale default
            $value['defaults'] = array_merge(array('locale' => $defaultLocale ), $defaults);

            //$routes[$key] = $value;

            // Get our route and make sure to remove the first forward slash
            // since it's not needed.
            $routeString = $value['route'];
            $routeString = ltrim($routeString, '/\\');

            // Modify our normal route to have the locale parameter.
            if (!isset($value['type']) || $value['type'] === 'Zend_Controller_Router_Route') {
                $value['route'] = ':locale/' . $routeString;
                $value['reqs']['locale'] = $requiredLocalesRegex;
                $localizedRoutes['locale_' . $key] = $value;
            } else if ($value['type'] === 'Zend_Controller_Router_Route_Regex') {
                $value['route'] = '(' . join('|', $locales) . ')\/' . $routeString;

                // Since we added the local regex match, we need to bump the existing
                // match numbers plus one.
                $map = isset($value['map']) ? $value['map'] : array();
                foreach ($map as $index => $word) {
                    unset($map[$index++]);
                    $map[$index] = $word;
                }

                // Add our locale map
                $map[1] = 'locale';
                ksort($map);

                $value['map'] = $map;

                $localizedRoutes['locale_' . $key] = $value;
            } elseif ($value['type'] === 'Zend_Controller_Router_Route_Static') {
                foreach ($locales as $locale) {
                    $value['route'] = $locale . '/' . $routeString;
                    $value['defaults']['locale'] = $locale;
                    $routes['locale_' . $locale . '_' . $key] = $value;
                }
            }
        }
        return $localizedRoutes;
    }
public static function getLocalizedRoutes ( array $ routes , array $ locales ) { $ localizedRoutes = array ( ) ; $ defaultLocale = self :: getDefaultLocale ( ) ; $ requiredLocalesRegex = '^(' . join ( '|' , $ locales ) . ')$' ; foreach ( $ routes as $ key => $ value ) { // First let's add the default locale to this routes defaults. $ defaults = isset ( $ value [ 'defaults' ] ) ? $ value [ 'defaults' ] : array ( ) ; // Always default all routes to the Zend_Locale default $ value [ 'defaults' ] = array_merge ( array ( 'locale' => $ defaultLocale ) , $ defaults ) ; //$routes[$key] = $value; // Get our route and make sure to remove the first forward slash // since it's not needed. $ routeString = $ value [ 'route' ] ; $ routeString = ltrim ( $ routeString , '/\\' ) ; // Modify our normal route to have the locale parameter. if ( ! isset ( $ value [ 'type' ] ) || $ value [ 'type' ] === 'Zend_Controller_Router_Route' ) { $ value [ 'route' ] = ':locale/' . $ routeString ; $ value [ 'reqs' ] [ 'locale' ] = $ requiredLocalesRegex ; $ localizedRoutes [ 'locale_' . $ key ] = $ value ; } else if ( $ value [ 'type' ] === 'Zend_Controller_Router_Route_Regex' ) { $ value [ 'route' ] = '(' . join ( '|' , $ locales ) . ')\/' . $ routeString ; // Since we added the local regex match, we need to bump the existing // match numbers plus one. $ map = isset ( $ value [ 'map' ] ) ? $ value [ 'map' ] : array ( ) ; foreach ( $ map as $ index => $ word ) { unset ( $ map [ $ index ++ ] ) ; $ map [ $ index ] = $ word ; } // Add our locale map $ map [ 1 ] = 'locale' ; ksort ( $ map ) ; $ value [ 'map' ] = $ map ; $ localizedRoutes [ 'locale_' . $ key ] = $ value ; } elseif ( $ value [ 'type' ] === 'Zend_Controller_Router_Route_Static' ) { foreach ( $ locales as $ locale ) { $ value [ 'route' ] = $ locale . '/' . $ routeString ; $ value [ 'defaults' ] [ 'locale' ] = $ locale ; $ routes [ 'locale_' . $ locale . '_' . $ key ] = $ value ; } } } return $ localizedRoutes ; }
Generate localized versions of routes

@param array $routes The originals
@param array $locales
@return array
Generate localized versions of routes