Internationalize your urls
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist pheme/yii2-i18n-url "dev-master"
or add
"pheme/yii2-i18n-url": "dev-master"
to the require section of your composer.json
file.
In your configuration file, add or replace your UrlManager component:
'components' => [
'urlManager' => [
'class' => 'pheme\i18n\I18nUrlManager',
//'displaySourceLanguage' => true,
//'rewriteBaseUrl' => true,
//'languageParam' => 'lang',
'languages' => ['en', 'gr'],
'aliases' => [],
// 'aliases' => ['en' => 'en-US', 'sr' => 'sr-Latn'],
// The keys will become labels on the language switcher widget
// 'languages' => ['English' => 'en', 'Ελληνικά' => 'gr']
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [],
],
...
]
Example of changing the language
<?= Html::a('Ελληνικά', ['site/index', 'lang' => 'gr']); ?>
Example of using the language switcher
<?= pheme\i18n\widgets\LanguageSwitcher::widget(); ?>