JMSI18nRoutingBundle icon indicating copy to clipboard operation
JMSI18nRoutingBundle copied to clipboard

-

Open ssalat opened this issue 11 years ago • 2 comments

ssalat avatar Jun 15 '13 23:06 ssalat

Sounds good.

If you can work on an implementation, that would be great!

schmittjoh avatar Jun 16 '13 08:06 schmittjoh

We had a similar problem recently, and solved it quite simply in our own application by overriding the DefaultPatternGenerationStrategy. For the above 'en_US' example, we tell JMSI18nRoutingBundle:

locales: ['en_US']

Our PatternGenerationStrategy has this:

    public function generateI18nPatterns($routeName, Route $route)
    {
        $patterns = parent::generateI18nPatterns($routeName, $route);

        foreach ($patterns as $key => $pattern) {
            // replace '/en_US/...' with '/en'
            unset($patterns[$key]);

            $replaced = preg_replace("/^\/en_US(.+)$/", "/en$1", $key);
            $patterns[$replaced] = [$locale];

        }

        return $patterns;
    }

(ours is actually configurable, the above is an example)

So this is possible to do with the existing bundle, you just have to override the default strategy. @schmittjoh is the proper solution here to document this capability, or to make it more easily accessible by providing the configuration that @ssalat proposes? Either way I'd be happy to take a look in my free time.

mguzman avatar Aug 06 '13 23:08 mguzman