Task Definition
So, you need localised urls made simple that follow the Yii framework guidelines?
http://example.com/terms-and-conditions (english)
http://example.com/impressum (german)
http://example.com/mentions-legales (french)
It's actually pretty simple to do!
This How-To assumes the following
You know how to use Yii framework
You know how to use the translations generator
You know how to use the Yii::t(...) function
Identifying the problem
The simplest solution to just translate them in the config UrlManager component right?
This way you will even get your routes translation file auto updated when you generate translations via the Yii cli script!
It sounds good doesn't it?!
However, this will NOT work because your translator is initialized after your configuration array is evaluated!
Solution
Bootstrap your Yii (as recommended by Qiang Xue)
Create a file Yii.php in the protected.components folder and create a class called Yii extending the YiiBase
At the moment Yii::createComponent allows you to pass in constructor arguments as extra arguments in the function. However we want to pass in extra arguments through our configuration array (we will need this for our super simplified UrlRule component later)
This is perfectly fine since you can't have variable with numeric names in PHP.
Our overload looks like this (copy/paste from the createComponent source with a couple of extra lines of code).
Of course we now need to use our Bootstrapping class instead of the default empty class provided by the framework. To do this we need to go to our public folder and edit the index.php
Finally, in the protected.components create a new Url rule component as following
In the end
If you modified everything correctly you can now write things like the following in your main.php config file
The implementation is rather easy and by updating your translations you can always easily modify the localized routes (which are auto-generated) in the routes.php translations file.