Revision #27 has been created by oligalma on Jun 25, 2017, 1:40:07 PM with the memo:
some changes
« previous (#26) next (#28) »
Changes
Title
unchanged
How to have truly multilingual URLs
Category
unchanged
How-tos
Yii version
unchanged
Tags
unchanged
multilingual, multilanguage, url, multilingual url, multilanguage url
Content
changed
[...]
We can easily have a multilingual site if we put a "lang" parameter that comes via GET. For example:
```php
<?php
echo CHtml::link('GameTutorials', array('/site/
gametutorials', 'lang' => 'en'));
echo CHtml::link('
JuegoTutoriales', array('/site/
gametutorials', 'lang' => 'es'));
echo CHtml::link('Services', array('/site/services', 'lang' => 'en'));
echo CHtml::link('Servicios', array('/site/services', 'lang' => 'es'));[...]
This leads to URLs like these:
- http://www.oligalma.com/en/gametutorials (English)
- http://www.oligalma.com/es/
gametutorials (Spanish)
- http://www.oligalma.com/en/services (English)
- http://www.oligalma.com/es/services (Spanish)[...]
This is fine to have a multilingual site. But, we can go one step further. What if we want URLs like these:
- [http://www.oligalma.com/en/gametutorials](http://www.oligalma.com/en/
gametutorials "") (English)
- [http://www.oligalma.com/es/
juegotutoriales](http://www.oligalma.com/es/
juegotutoriales "") (Spanish)
- [http://www.oligalma.com/en/services](http://www.oligalma.com/en/services "") (English)
- [http://www.oligalma.com/es/servicios](http://www.oligalma.com/es/servicios "") (Spanish)[...]
'rules'=>array(
'<lang:\w+>'=>'site/index',
'<lang:es>/juegotutoriales'=> 'site/
gametutorials',
'<lang:en>/
gametutorials'=> 'site/
gametutorials',
'<lang:es>/servicios'=> 'site/services',
'<lang:en>/services'=> 'site/services',
'<lang:\w+>/<action>' => 'site/<action>',
)
),[...]