Search by

yii2-extensions / localeurls

terabytesoftw

Automatic locale/language management for URLs.

Package info

github.com/yii2-extensions/localeurls

Homepage

Documentation

pkg:composer/yii2-extensions/localeurls

Statistics

Installs: 6 736

Dependents: 0

Suggesters: 0

Stars: 3

Open Issues: 0

0.2.1 2026-10-23 15:29 UTC

This package is auto-updated.

Last update: 2026-10-23 15:34:11 UTC


README

Yii Framework

Locale URLs


PHPUnit Mutation Testing PHPStan Security

Language detection, persistence, and locale-aware URLs for Yii2 applications

Features

Feature Overview

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

  1. Detects the language from the URL path (/es/about sets Spanish).
  2. Falls back to the persisted language, then to browser headers or GeoIP, then to the default language.
  3. Adds the language code to generated URLs, except for the default language (see enableDefaultLanguageUrlCode).
  4. 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.

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.

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

PHP Yii 2.0.55+ Yii 22.0.x Latest Stable Version Total Downloads

Project status

Codecov PHPStan Level Max Quality StyleCI

Our social networks

Follow on X Follow on Facebook Join our Subreddit Join on Telegram

Credits

This package started as a fork of codemix/yii2-localeurls.

License

License