domprojects/codeigniter4-localize
最新稳定版本:v1.0.1
Composer 安装命令:
composer require domprojects/codeigniter4-localize
包简介
Locale management and URL localization filter for CodeIgniter 4 projects.
README 文档
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
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-02