Skip to content

Commit 2341bf9

Browse files
Minor rewords and fixes
1 parent f7c8839 commit 2341bf9

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

routing.rst

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,11 @@ use them later to :ref:`generate URLs <routing-generate>`.
141141
Localized Routing (i18n)
142142
------------------------
143143

144-
Routes can be localized to provide unique paths per *locale*. Symfony provides a
145-
handy way to declare localized routes without duplication.
144+
.. versionadded:: 4.1
145+
The feature to localize routes was introduced in Symfony 4.1.
146+
147+
Routes can be localized to provide unique paths per :doc:`locale </translation/locale>`.
148+
Symfony provides a handy way to declare localized routes without duplication.
146149

147150
.. configuration-block::
148151

@@ -154,30 +157,18 @@ handy way to declare localized routes without duplication.
154157
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
155158
use Symfony\Component\Routing\Annotation\Route;
156159
157-
class BlogController extends Controller
160+
class CompanyController extends Controller
158161
{
159162
/**
160-
* Matches /blog exactly
161-
*
162-
* @Route("/blog", name="blog_list")
163+
* @Route({
164+
* "nl": "/over-ons",
165+
* "en": "/about-us"
166+
* }, name="about_us")
163167
*/
164-
public function list()
168+
public function about()
165169
{
166170
// ...
167171
}
168-
169-
/**
170-
* Matches /blog/*
171-
*
172-
* @Route("/blog/{slug}", name="blog_show")
173-
*/
174-
public function show($slug)
175-
{
176-
// $slug will equal the dynamic part of the URL
177-
// e.g. at /blog/yay-routing, then $slug='yay-routing'
178-
179-
// ...
180-
}
181172
}
182173
183174
.. code-block:: yaml
@@ -214,7 +205,7 @@ handy way to declare localized routes without duplication.
214205
->controller('App\Controller\CompanyController::about');
215206
};
216207
217-
When a localized route is matched Symfony will automatically know which locale
208+
When a localized route is matched Symfony automatically knows which locale
218209
should be used during the request. Defining routes this way also eliminated the
219210
need for duplicate registration of routes which minimizes the risk for any bugs
220211
caused by definition inconsistency.
@@ -695,16 +686,16 @@ But if you pass extra ones, they will be added to the URI as a query string::
695686
// /blog/2?category=Symfony
696687

697688
Generating Localized URLs
698-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
689+
~~~~~~~~~~~~~~~~~~~~~~~~~
699690

700-
When you've defined localized routes Symfony will use the current request locale
701-
as the default when generating routes. In order to generate the route for alternative
702-
locale you must pass the ``_locale`` in the parameters array::
691+
When a route is localized, Symfony uses by default the current request locale to
692+
generate the URL. In order to generate the route for a different locale you must
693+
pass the ``_locale`` in the parameters array::
703694

704695
$this->router->generate('about_us', array(
705696
'_locale' => 'nl',
706697
));
707-
// /over-ons
698+
// generates: /over-ons
708699

709700
Generating URLs from a Template
710701
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)