So, I’m fairly new to Yii Framework, I’m doing a job on an app my costumer bought that was made on Yii Framework 1.1
He needs me to have the URLs translated, so I’m looking for ways to do it.
I noticed that the URLs that have static names, like:
Can be easily added a translation like so:
Though I wanted to translate controllers as well, if possible, using the translation files so I could add more languages by just adding translation files for other languages instead of setting them in the URL manager.
Also, there are the routes assigned like this one that I wish to translate:
'<action:(page|otherpage|anotherone)>' => 'store/<action>',
So I’m uncertain of the best way to procceed, and also, wish to know the best way to make the URLs on the website automatically follow the selected language
Thanks in advance!!
So, I managed to find a way. to do it.
First of all, I added the translated page names from the
'<action:(page|otherpage|anotherone)>' => 'store/<action>', manually and individually, since they weren’t so many and they were all written in one place and easy to do, so it became:
'page' => 'store/page',
'anotherpage' => 'store/anotherpage',
And so on… I’ve also done the same for the controllers, but there weren’t many anyway.
Then the part that saved me the most work was this one: I slipped a Yii:t() function on the UrlManager component createUrl function!!
$route = Yii::t('urls',$route);
So it was a matter of creating a translation file for the URLs with basically the same thing added to the UrlManager, only in another order (didn’t even write those by hand, made a script to write those for me).
So far, so good, but there is something that these modifications couldn’t fix right away was the URLs being generated dinamically by things like
Yii::app()->createUrl('/stuff/'.$slug), since they’re dynamic, I’m not going to hardcode each of the slugs… How would I go about translating those URLs as well, without having to go to each and every place that these urls are generated and changing the generation code? Can I regex within the t() function?