jrmajor/laravel-fluent
Composer 安装命令:
composer require jrmajor/laravel-fluent
包简介
Fluent translations for Laravel
关键字:
README 文档
README
Unleash the expressive power of the natural language in your Laravel application with Project Fluent, a localization system designed by Mozilla.
Read the Fluent Syntax Guide or try it out in the Fluent Playground to learn more about the syntax.
shared-photos =
{ $userName } { $photoCount ->
[one] added a new photo
*[other] added { $photoCount } new photos
} to { $userGender ->
[male] his stream
[female] her stream
*[other] their stream
}.
__('stream.shared-photos', [ 'userName' => 'jrmajor', 'photoCount' => 2, 'userGender' => 'male', ]); // jrmajor added 2 new photos to his stream.
This package is a Laravel wrapper around jrmajor/fluent-php.
You may install it via Composer: composer require jrmajor/laravel-fluent. The package will automatically register itself.
Usage
This package replaces default Laravel translator with Major\Fluent\Laravel\FluentTranslator.
app('translator') instanceof Major\Fluent\Laravel\FluentTranslator; // true
Fluent translations are stored in .ftl files. Place them among your .php translation files in your Laravel app:
/resources
/lang
/en
menu.ftl
validation.php
/pl
menu.ftl
validation.php
If there is no Fluent message for a given key, translator will fall back to a .php file, which allows you to introduce Fluent translation format progressively.
Laravel validator uses custom logic for replacing the :attribute variable and requires deeply nested keys, which are not supported in Fluent, so you should leave validation.php file in the default Laravel format.
The trans_choice() helper always falls back to the default translator, as the Fluent format eliminates the need for this function.
You may use the FluentTranslator::addFunction() method to register Fluent functions.
Configuration
Optionally, you can publish the configuration file with this command:
php artisan vendor:publish --tag fluent-config
This will publish the following file in config/fluent.php:
return [ /* * In strict mode, exceptions will be thrown for syntax errors * in .ftl files, unknown variables in messages etc. * It's recommended to enable this setting in development * to make it easy to spot mistakes. */ 'strict' => env('APP_ENV', 'production') !== 'production', /* * Determines if it should use Unicode isolation marks (FSI, PDI) * for bidirectional interpolations. You may want to enable this * behaviour if your application uses right-to-left script. */ 'use_isolating' => false, ];
Testing
vendor/bin/phpunit # Tests vendor/bin/phpstan analyze # Static analysis vendor/bin/php-cs-fixer fix # Formatting
jrmajor/laravel-fluent 适用场景与选型建议
jrmajor/laravel-fluent 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.77k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2021 年 05 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「i18n」 「translation」 「locale」 「language」 「l10n」 「translator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jrmajor/laravel-fluent 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jrmajor/laravel-fluent 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jrmajor/laravel-fluent 相关的其它包
同方向 / 同关键字的高下载量 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
统计信息
- 总下载量: 8.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 20
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-29