domprojects / codeigniter4-localize
Locale management and URL localization filter for CodeIgniter 4 projects.
Package info
github.com/domProjects/codeigniter4-localize
pkg:composer/domprojects/codeigniter4-localize
Requires
- php: ^8.2
- codeigniter4/framework: ^4.7.2
This package is auto-updated.
Last update: 2026-04-02 13:06:49 UTC
README
Locale management and URL localization filter for CodeIgniter 4.
This package adds a reusable localization filter that can:
- detect the visitor locale
- redirect root requests like
/to/{locale} - redirect requests without locale prefix to
/{locale}/... - persist the active locale in session and cookie
- validate locale segments against
Config\App::$supportedLocales
Installation
composer require domprojects/codeigniter4-localize
How It Works
The package registers a localize filter automatically through a Registrar.
It does not modify app/Config/Filters.php manually.
Configuration
The package uses two configuration sources:
Config\AppdomProjects\CodeIgniterLocalize\Config\Localize
You should configure your project locales in app/Config/App.php:
public string $defaultLocale = 'en'; public array $supportedLocales = ['en', 'fr'];
Optional package behavior can be customized by creating:
app/Config/Localize.php
Example:
<?php namespace Config; use domProjects\CodeIgniterLocalize\Config\Localize as BaseLocalize; class Localize extends BaseLocalize { public bool $redirectRoot = true; public bool $redirectMissingLocale = true; public string $invalidLocaleBehavior = '404'; public array $excluded = [ 'api/*', 'assets/*', 'favicon.ico', 'robots.txt', ]; }
Recommended Behavior
Locale priority:
- locale found in URL
- locale stored in session
- locale stored in cookie
- browser language
Config\App::$defaultLocale
Recommended request behavior:
/redirects to/{locale}/aboutredirects to/{locale}/about/fr/aboutappliesfr/zz/aboutreturns404wheninvalidLocaleBehavior = '404'- assets and technical paths stay excluded from localization
Routes
For locale-prefixed URLs, a route group like this is recommended:
$routes->useSupportedLocalesOnly(true); $routes->group('{locale}', static function ($routes) { $routes->get('/', 'Home::index'); $routes->get('about', 'Pages::about'); });
If your application does not use locale prefixes in routes, you can disable automatic redirection in the package config.
Package Structure
src/
Config/
Localize.php
Registrar.php
Filters/
Localize.php
License
MIT