niels-numbers/laravel-localizer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

niels-numbers/laravel-localizer

最新稳定版本:v1.3.0

Composer 安装命令:

composer require niels-numbers/laravel-localizer

包简介

Detects the user’s preferred language and redirects to the matching localized URL.

README 文档

README

Tests PHP Laravel License

Successor to mcamara/laravel-localization. Static routes, route:cache ready.

Locale-aware routing for Laravel: auto-detect, auto-redirect, and resolve route() per language.

Documentation: localizer.adam-nielsen.de

Example

Route::localize(function () {
    Route::get('/about', AboutController::class)->name('about');
});

Produces:

  • /about - this endpoint carries the package's core magic: auto-detection, redirect, or default locale (see below)
  • /de/about, /fr/about, ... for every other configured locale

Every route is registered twice as a static route:

GET|HEAD  about ............... without_locale.about › AboutController
GET|HEAD  {locale}/about .......... with_locale.about › AboutController

In your application code, keep using route('about'); the package picks the right variant based on the current locale.

How /about resolves at request time:

  1. First visit: the package reads the Accept-Language header (or your own detector chain) and redirects to the matching localized URL.
  2. Subsequent visits: an explicit URL prefix always wins. Without a URL signal, the locale is taken from the session and cookie. The user is redirected to the prefixed variant unless their locale matches the default and hide_default_locale is on - in which case they are redirected or stay on /about.
  3. Fallback: when no signal matches, the configured default locale is used.

Note: a switcher link to plain /about carries no locale signal - RedirectLocale would send the user back to their session locale instead of switching. See Language Switcher for more.

Install

composer require niels-numbers/laravel-localizer

Setup guide · Migrating from mcamara/laravel-localization?

License & credits

MIT licensed. Created by Adam Nielsen, building on prior work by @mcamara (original laravel-localization), @codezero-be (deprecated laravel-localized-routes, whose static-route ideas inspired this rewrite) and @jordyvanderhaegen (current maintainer of the original, whose issue #921 motivated this package).

统计信息

  • 总下载量: 464
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固