定制 domprojects/codeigniter4-localize 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

domprojects/codeigniter4-localize

最新稳定版本:v1.0.1

Composer 安装命令:

composer require domprojects/codeigniter4-localize

包简介

Locale management and URL localization filter for CodeIgniter 4 projects.

README 文档

README

Packagist License PHPUnit Psalm PHPStan

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:

  1. Config\App
  2. domProjects\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:

  1. locale found in URL
  2. locale stored in session
  3. locale stored in cookie
  4. browser language
  5. Config\App::$defaultLocale

Recommended request behavior:

  • / redirects to /{locale}
  • /about redirects to /{locale}/about
  • /fr/about applies fr
  • /zz/about returns 404 when invalidLocaleBehavior = '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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固