palgoals/locale-package
Composer 安装命令:
composer require palgoals/locale-package
包简介
A Laravel package for database-driven multilingual support with language switcher, translation management, and RTL/LTR auto-detection.
README 文档
README
A Laravel package for database-driven multilingual support with language management, translation CRUD, RTL/LTR auto-detection, and ready-to-use Blade components.
Features
- ✅ Database-driven translations with
t('key')helper - ✅ Auto-create missing translation keys in the DB
- ✅ Cache per key/locale pair (configurable TTL)
- ✅ Fallback locale chain
- ✅ RTL / LTR auto-detection via
current_dir() - ✅ Language switcher Blade components (frontend + dashboard)
- ✅ Full CRUD admin panel for languages and translations
- ✅ Supports Laravel 10, 11, 12
Requirements
- PHP 8.1+
- Laravel 10 / 11 / 12
Installation
Step 1 — Install via Composer
composer require palgoals/locale-package
Step 2 — Run the installer
php artisan locale:install
This single command will:
- ✅ Publish all files (Models, Controllers, Middleware, Views, Routes, Config)
- ✅ Run migrations (creates
languagesandtranslation_valuestables)
Optional: Add
--seedto seed default languages automatically:php artisan locale:install --seed
Step 3 — Register the Helper
In your project's composer.json, add the helper to autoload:
"autoload": { "files": [ "app/helpers_locale.php" ] }
Then run:
composer dump-autoload
Step 4 — Register the Middleware
Laravel 11+ — in bootstrap/app.php:
->withMiddleware(function (Middleware $middleware) { $middleware->alias([ 'setLocale' => \App\Http\Middleware\SetLocale::class, ]); })
Laravel 10 and below — in app/Http/Kernel.php:
protected $middlewareAliases = [ 'setLocale' => \App\Http\Middleware\SetLocale::class, ];
Step 5 — Add Routes
In routes/web.php:
Route::middleware(['setLocale'])->group(function () { require __DIR__ . '/lang.php'; // ... your other routes });
In your dashboard routes file (inside auth/admin group):
require __DIR__ . '/lang_dashboard.php';
Step 6 — Share Variables with All Views
In app/Providers/AppServiceProvider.php inside boot():
view()->composer('*', function ($view) { $view->with([ 'currentLocale' => app()->getLocale(), 'currentLanguage' => \App\Models\Language::where('code', app()->getLocale())->first(), 'languages' => \App\Models\Language::where('is_active', true)->get(), ]); });
Usage
Translate text
{{ t('frontend.nav.home') }} {{ t('frontend.hero.title', 'Welcome') }} {!! t_html('frontend.about.description') !!}
Page direction (RTL / LTR)
<html dir="{{ current_dir() }}" lang="{{ app()->getLocale() }}">
Language Switcher (Frontend)
<x-lang.language-switcher /> <x-lang.language-switcher variant="topbar" />
Language Switcher (Dashboard)
<x-lang.language-switcher-dashboard />
CMS Page Slug (optional — requires App\Models\Page)
<a href="/{{ page_slug('about') }}">{{ t('frontend.nav.about') }}</a>
Configuration
After installation, edit config/palgoals-locale.php:
return [ // Optional: resolve default language from your own settings model 'default_language_resolver' => function () { return \App\Models\GeneralSetting::first()?->default_language_code ?? config('app.locale'); }, // Auto-create missing translation keys in the DB 'auto_create' => env('TRANSLATION_AUTO_CREATE', true), // Cache duration in seconds 'cache_ttl' => env('TRANSLATION_CACHE_TTL', 60), ];
.env options
TRANSLATION_AUTO_CREATE=true TRANSLATION_CACHE_TTL=60 APP_LOCALE=ar APP_FALLBACK_LOCALE=en
Views Note
The dashboard views (resources/views/dashboard/lang/) depend on your project's layout components:
<x-dashboard-layout>— your project's dashboard layout<x-form.input>— your project's input component
Edit these views after installation to match your project's component names.
License
MIT — © PalGoals
palgoals/locale-package 适用场景与选型建议
palgoals/locale-package 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「i18n」 「translation」 「locale」 「laravel」 「multilingual」 「rtl」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 palgoals/locale-package 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 palgoals/locale-package 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 palgoals/locale-package 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use i18n translation PHP class for multi-language websites
Package for convenient work with Laravel's localization features
A custom URL rule class for Yii 2 which allows to create translated URL rules
A Laravel Eloquent model trait for translatable resource
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
Nette Framework adapter for I18n package
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 43
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-13