yii2-extensions / localeurls
Automatic locale/language management for URLs.
Requires
- php: >=8.3
- yiisoft/yii2: ~2.0.55 || ^22.0@dev
Requires (Dev)
- infection/infection: ^0.35
- maglnet/composer-require-checker: ^4.1
- php-forge/coding-standard: ^0.3
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-phpunit: ^2.0
- phpstan/phpstan-strict-rules: ^2.0.3
- phpunit/phpunit: ^12.5
- yii2-extensions/phpstan: ^0.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-23 15:34:11 UTC
README
Locale URLs
Language detection, persistence, and locale-aware URLs for Yii2 applications
Features
Worker-mode requirements (sessions, cookies, event handlers) are listed in the configuration guide.
Installation
composer require yii2-extensions/localeurls:^0.2
Quick start
How it works
- Detects the language from the URL path (
/es/aboutsets Spanish). - Falls back to the persisted language, then to browser headers or GeoIP, then to the default language.
- Adds the language code to generated URLs, except for the default language (see
enableDefaultLanguageUrlCode). - Remembers the choice in session and cookie.
Basic configuration
Replace the urlManager component in config/web.php. The application language is the default language, which has no
code in the URL; the defaultLanguage property of the manager sets it explicitly.
<?php declare(strict_types=1); use yii2\extensions\localeurls\UrlLanguageManager; return [ 'language' => 'en', 'components' => [ 'urlManager' => [ 'class' => UrlLanguageManager::class, 'languages' => ['en', 'es', 'fr', 'de'], 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ '' => 'site/index', '<controller:\w+>/<action:\w+>' => '<controller>/<action>', ], ], ], ];
Automatic URL generation
<?php declare(strict_types=1); use yii\helpers\Url; // Current language `en`, the default language. Url::to(['site/about']); // /site/about // Current language `es`, set by a request such as /es/site/index. Url::to(['site/about']); // /es/site/about // Another language. Url::to(['site/contact', 'language' => 'fr']); // /fr/site/contact
Documentation
Practical guides and examples for language-aware URLs and worker isolation.
- ๐ Installation Guide
- โ๏ธ Configuration Guide, including worker mode
- ๐ก Usage Examples
- ๐ Upgrade Guide
- ๐งช Testing Guide
The guides and the API reference generated
from the PHPDoc in src/ are published at https://yii2-framework.github.io/docs/extensions/localeurls/.
AI assistance
AI agents: read the documentation index and fetch the Markdown version
of a page by appending index.md to its URL. The
AI agents guide covers skill installation, client setup and
verification.
- ๐ค
yii2-localeurls-configurationskill: Language URLs. - ๐งญ
yii2-frameworkskill: Yii 22.0 application conventions.
The hosted documentation covers Yii 22.0. If it does not match the installed revision or is unavailable, use the repository guides, the skill source, the source PHPDoc and the changelog.
Package information
Project status
Our social networks
Credits
This package started as a fork of codemix/yii2-localeurls.