rdcstarr/laravel-locale
Composer 安装命令:
composer require rdcstarr/laravel-locale
包简介
Database-driven language and country management for Laravel.
README 文档
README
Database-driven language and country management for Laravel 13.
- Languages — ISO 639-1, enabled/default flags
- Countries — ISO 3166-1 alpha-2, flag emoji, timezone, E.164 calling code, primary language
- Octane-safe — stateless singleton service, current locale read dynamically per request
Requirements
| Dependency | Version |
|---|---|
| PHP | ^8.3 |
| Laravel | ^13.0 |
Installation
composer require rdcstarr/laravel-locale
Run the install command to publish and run migrations, then seed languages, countries and their relationships:
php artisan locale:install
Manual installation
If you prefer to control the process yourself, publish the migrations without running the install command:
php artisan vendor:publish --tag=laravel-locale-migrations
Then run the migrations and seed the reference data:
php artisan migrate php artisan db:seed --class="Rdcstarr\Locale\Database\Seeders\LanguagesSeeder" php artisan db:seed --class="Rdcstarr\Locale\Database\Seeders\CountriesSeeder" php artisan db:seed --class="Rdcstarr\Locale\Database\Seeders\CountryLanguageSeeder"
Note: Migrations run automatically without publishing — skip
vendor:publishif you do not need to modify the migration files.
Languages
use Locale; // All enabled languages Locale::enabledLanguages(); // Default language Locale::defaultLanguage(); // Find by ISO 639-1 code Locale::languageByCode('ro'); // code → id map (useful for seeding) Locale::enabledLanguageCodeToId(); // Raw query builder Locale::languages()->where('enabled', true)->get();
Countries
use Locale; // Find by ISO 3166-1 alpha-2 code Locale::countryByCode('RO'); // Phone prefix (ITU-T E.164, e.g. "+40") Locale::callingCodeByCode('RO'); // → "+40" country_calling_code('RO'); // → "+40" (global helper) Locale::countryByCode('RO')->calling_code; // direct model access // All countries sharing a calling code (e.g. NANP "+1") Locale::countries()->byCallingCode('+1')->get(); // All countries that use a given language Locale::countriesForLanguage('ro'); // code → id map (useful for seeding) Locale::countryCodeToId(); // Raw query builder Locale::countries()->with('primaryLanguage')->get();
Models
Language
| Column | Type | Notes |
|---|---|---|
id |
bigint | |
name |
string | e.g. Romanian |
code |
string(5) | ISO 639-1, e.g. ro |
enabled |
boolean | default true |
default |
boolean | default false |
Country
| Column | Type | Notes |
|---|---|---|
id |
bigint | |
name |
string | e.g. Romania |
code |
string(2) | ISO 3166-1 alpha-2, e.g. RO |
flag |
string | URL or path |
flag_emoji |
string | e.g. 🇷🇴 |
timezone |
string | e.g. Europe/Bucharest |
calling_code |
string(10) | ITU-T E.164, e.g. +40, +1 |
primary_language_id |
FK → languages |
The country_language pivot table stores all official languages per country with an is_official boolean.
Octane compatibility
LocaleService is registered as a singleton but stores no request-scoped state — the current locale is always read dynamically via app()->getLocale(), so it is safe to reuse across requests on a long-lived worker.
rdcstarr/laravel-locale 适用场景与选型建议
rdcstarr/laravel-locale 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「i18n」 「locale」 「language」 「l10n」 「laravel」 「country」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rdcstarr/laravel-locale 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rdcstarr/laravel-locale 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rdcstarr/laravel-locale 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
Easy to use i18n translation PHP class for multi-language websites
Package for convenient work with Laravel's localization features
Store your language lines in the database, yaml or other sources
A custom URL rule class for Yii 2 which allows to create translated URL rules
Set Links with a specific language parameter
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-18