codezero/laravel-uri-translator
Composer 安装命令:
composer require codezero/laravel-uri-translator
包简介
Translate a URI or individual slugs.
README 文档
README
This package registers a macro for the Laravel Translator class.
This will allow you to translate individual URI slugs, while ignoring parameter placeholders.
Parameters will not be translated by this macro. That remains the responsibility of your code.
✅ Requirements
- PHP >= 8.1
- Laravel >= 10.0
📦 Install
Install this package with Composer:
composer require codezero/laravel-uri-translator
Laravel will automatically register the ServiceProvider.
In your app's lang folder, create subdirectories for every locale you want to have translations for.
Next create a routes.php file in each of those directories.
lang/
├── en/
│ └── routes.php
└── nl/
└── routes.php
Return an array of translations from the routes.php files.
🚀 Usage
Use the Lang::uri() macro when registering routes:
Route::get(Lang::uri('hello/world'), [Controller::class, 'index']);
The URI macro accepts 2 additional parameters:
- A locale, in case you need translations to a locale other than the current app locale.
- A namespace, in case your translation files reside in a package.
Lang::uri('hello/world', 'fr', 'my-package');
You can also use trans()->uri('hello/world') instead of Lang::uri('hello/world').
🔌 Example
Using these example translations:
// lang/nl/routes.php return [ 'hello' => 'hallo', 'world' => 'wereld', 'override/hello/world' => 'something/very/different', 'hello/world/{parameter}' => 'uri/with/{parameter}', ];
These are possible translation results:
// Translate every slug individually // Translates to: 'hallo/wereld' Lang::uri('hello/world'); // Keep original slug when missing translation // Translates to: 'hallo/big/wereld' Lang::uri('hello/big/world'); // Translate slugs, but not parameter placeholders // Translates to: 'hallo/{world}' Lang::uri('hello/{world}'); // Translate full URIs if an exact translation exists // Translates to: 'something/very/different' Lang::uri('override/hello/world'); // Translate full URIs if an exact translation exists (with placeholder) // Translates to: 'uri/with/{parameter}' Lang::uri('hello/world/{parameter}');
🚧 Testing
composer test
☕️ Credits
🔒 Security
If you discover any security related issues, please e-mail me instead of using the issue tracker.
📑 Changelog
A complete list of all notable changes to this package can be found on the releases page.
📜 License
The MIT License (MIT). Please see License File for more information.
codezero/laravel-uri-translator 适用场景与选型建议
codezero/laravel-uri-translator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 369.26k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2023 年 03 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「url」 「locale」 「language」 「uri」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 codezero/laravel-uri-translator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 codezero/laravel-uri-translator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 codezero/laravel-uri-translator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Package for convenient work with Laravel's localization features
Easy URL rewrites in your Laravel application
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
A Lithium plugin with additional g11n resources constituting the Lithium Locale Data Repository.
A Laravel helper to detect if the current route/path is active.
Provides a service and twig extension for getting short urls like http://your.host/~short
统计信息
- 总下载量: 369.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 40
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-14