Locale URLs
هذا المحتوى غير متوفر بلغتك بعد.
Language detection, persistence, and locale-aware URLs for Yii2 applications
Features
Section titled “Features”Worker-mode requirements (sessions, cookies, event handlers) are listed in the configuration guide.
Installation
Section titled “Installation”composer require yii2-extensions/localeurls:^0.2Quick start
Section titled “Quick start”How it works
Section titled “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
Section titled “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
Section titled “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/contactDocumentation
Section titled “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
AI assistance
Section titled “AI assistance”AI agents: use the repository guides and source for the installed revision.
For a documentation deployment with
llms.txt, read that index first. When Markdown export is enabled, append
index.md to a page URL. For Yii conventions, use the yii2-framework skill
from a local framework documentation checkout.
- 🤖 yii2-localeurls-configuration skill: installation for Claude Code, Codex, and OpenCode.
If the hosted sources are unavailable, use the repository guides and locally available skills.
Our social networks
Section titled “Our social networks”Follow on X Follow on Facebook Join our Subreddit Join on Telegram
Credits
Section titled “Credits”This package started as a fork of codemix/yii2-localeurls.
License
Section titled “License”Package
Section titled “Package”- Source code and issues: yii2-extensions/localeurls. Star the repository if the package is useful to you.
- Composer package: yii2-extensions/localeurls.
- Changelog: CHANGELOG.md.