albertofem/translatableroutepath-bundle

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

JpnForPhp Symfony2 bundle integration

dev-master 2014-11-30 15:14 UTC

This package is not auto-updated.

Last update: 2021-11-27 01:19:41 UTC


README

build status Scrutinizer Code Quality

Allows using translations in routes paths:

/**
 * @Route("/[my.translatable.key]/route/{param}", options={"translatable"=true})
 */
public function myAction()
{
}

If my.transatable.key is defined in English as: my_translatable_route, this will produce a route:

/my_translatable_route/route/whatever_param

Installation

Require it in composer:

composer require albertofem/translatableroutepath-bundle dev-master

Install it:

composer update albertofem/translatableroutepath-bundle

Add it to your bundles:

$bundles = array(
    ...,
    new \AFM\Bundle\TranslatableRoutePathBundle\AFMTranslatableRoutePathBundle()
);

Additionally, you can use this bundle with JMSI18nRoutingBundle in which case you will need to register it before this one:

$bundles = array(
    ...
    new \JMS\I18nRoutingBundle\JMSI18nRoutingBundle(),
    new \AFM\Bundle\TranslatableRoutePathBundle\AFMTranslatableRoutePathBundle()
);

If you need to run the tests:

./vendor/bin/phpunit

Usage

You need to add the option to your route to be translatable:

/**
 * @Route("/[my.translatable.key]/route/{param}", options={"translatable"=true})
 */
public function myAction()
{
}

Using YAML:

my_translatable_route:
    path: /[my.translatable.key]/route/{param}
    options: { translatable: true }

Use the syntax [...] to referer to translations in your routes paths. You can use this syntax in annotations/yaml/PHP indistintively.

Integration with JMSI18nRoutingBundle

If your are using this great bundle, routes will be automatically translated to all the locales set in the configuration.

Integration with Symfony core Router

When using Symfony core router, all routes are translated into the default locale. If you need a Route to be translated in another language, you must specify the _locale default parameter:

my_translatable_route:
    path: /[my.translatable.key]/route/{param}
    options: { translatable: true }
    defaults: { _locale: en } # this route will translated in English

TODO

  • Support parameters for translations (domains, etc.)
  • Support transChoice