pheme / yii2-i18n-url
Internationalize your urls
Installs: 4 195
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 6
Forks: 7
Open Issues: 1
Type:yii2-extension
Requires
This package is not auto-updated.
Last update: 2024-11-05 03:41:48 UTC
README
Internationalize your urls
Installation
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.
Usage
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(); ?>