lukasss93/laravel-larex
Composer 安装命令:
composer require lukasss93/laravel-larex
包简介
Translate your Laravel application from a single CSV file!
README 文档
README
Laravel Larex
Laravel Larex lets you translate your whole Laravel application with a single CSV file.
You can import translation entries from lang folder into a structured CSV, edit the translations and export them back to Laravel PHP files.
Laravel Larex also supports functionalities to sort entries and find strings that aren't localized yet.
See Plugins section for other features.
🚀 Installation
You can install the package using composer
composer require lukasss93/laravel-larex --dev
Then add the service provider to config/app.php.
This step can be skipped if package auto-discovery is enabled.
'providers' => [ Lukasss93\Larex\LarexServiceProvider::class ];
⚙ Publishing the config file
Publishing the config file is optional:
php artisan vendor:publish --provider="Lukasss93\Larex\LarexServiceProvider" --tag="larex-config"
👓 Usage
-
First, you must create the initial CSV file with
php artisan larex:init.
Or you can usephp artisan larex:importto import entries from lang folder.
The csv file has the following columns:- group (basically the file name)
- key (the array key)
- en (the language code)
- other language codes...
-
Open the project-root/lang/localization.csv file and edit it as you see fit.
-
Finally, you can use
php artisan larex:exportto translate your entries from the csv file to the laravel php files.
✨ Tips
- You can import existing laravel php files with
php artisan larex:import. - You can use
php artisan larex:init --baseto init the CSV file with default Laravel entries. - The key column inside the CSV file supports the dot notation for nested arrays.
- You can watch your CSV file with
php artisan larex:export --watch - You can use
php artisan larex:sortto sort the CSV file by group and key. - Be careful when using the
php artisan larex:exportcommand! It will overwrite all files named with the group names inside the CSV. - Be careful when using the dot notation! Only the last entry will override the value.
- You can use
php artisan larex:insertto add new items via CLI too! - You can use
php artisan larex:import --include=en,itto import only "en" and "it" items. - You can use
php artisan larex:import --exclude=itto import all items except "it" item. - You can use
php artisan larex:export --include=en,itto export only "en" and "it" columns. - You can use
php artisan larex:export --exclude=itto export all columns except "it" column. - You can use
php artisan larex:localizeto find unlocalized strings (use the--importoption to add strings in your CSV). - You can use
php artisan larex:findto search existing groups or keys in your CSV file. - You can use
php artisan larex:removeto remove existing strings in your CSV file. - You can use
php artisan larex:lang:addto add a new language column to your CSV file. - You can use
php artisan larex:lang:removeto remove a language column from your CSV file. - You can use
php artisan larex:lang:orderto reorder language columns in your CSV file.
📝 Example
-
Run
php artisan larex:initcommand -
Edit the project-root/lang/localization.csv file
| group | key | en | it |
|---|---|---|---|
| app | hello | Hello | Ciao |
| app | list.developers | Developers | Sviluppatori |
| app | list.teachers | Teachers | Insegnanti |
-
Run
php artisan larex:exportcommand -
You'll get the following files:
//project-root/lang/en/app.php <?php return [ 'hello' => 'Hello', 'list' => [ 'developers' => 'Developers', 'teachers' => 'Teachers', ] ];
//project-root/lang/it/app.php <?php return [ 'hello' => 'Ciao', 'list' => [ 'developers' => 'Sviluppatori', 'teachers' => 'Insegnanti', ] ];
⏫ Exporters
The larex:export <exporter> command exports CSV strings to a specific location based on the selected exporter.
| Exporter | Default | Description |
|---|---|---|
| laravel | ✅ | Export data from CSV to Laravel localization files |
| json:group | ❌ | Export data from CSV to JSON by group |
| json:lang | ❌ | Export data from CSV to JSON by language |
How to create an exporter:
- Create a class that implements the
Lukasss93\Larex\Contracts\Exporterinterface - Add your exporter inside the larex config
⏬ Importers
The larex:import <importer> command imports the strings of the selected importer, into the CSV.
| Importer | Default | Description |
|---|---|---|
| laravel | ✅ | Import data from Laravel localization files to CSV |
| json:group | ❌ | Import data from JSON by group to CSV |
| json:lang | ❌ | Import data from JSON by language to CSV |
How to create an importer:
- Create a class that implements the
Lukasss93\Larex\Contracts\Importerinterface - Add your importer inside the larex config
🔍 Linters
Larex provides a linting system by using the php artisan larex:lint command to validate your CSV file.
Available linters:
| Linter | Enabled by default |
Description |
|---|---|---|
| ValidHeaderLinter | ✅ | Validate the header structure |
| ValidLanguageCodeLinter | ✅ | Validate the language codes in the header columns |
| DuplicateKeyLinter | ✅ | Find duplicated keys |
| ConcurrentKeyLinter | ✅ | Find concurrent keys |
| NoValueLinter | ✅ | Find missing values |
| DuplicateValueLinter | ✅ | Find duplicated values in the same row |
| UntranslatedStringsLinter | ❌ | Find untranslated strings |
| UntranslatedStringsLinter | ❌ | Find unused strings |
| ValidHtmlValueLinter | ❌ | Check valid html values |
| SameParametersLinter | ❌ | Check same parameters in each language |
You can enable/disable any linter you want by comment/uncomment it inside the larex config.
How to create a linter:
- Create a class that implements the
Lukasss93\Larex\Contracts\Linterinterface - Add your linter inside the larex config
🧩 Plugins
- Crowdin Plugin
A Laravel Larex plugin to import/export localization strings from/to Crowdin
⚗️ Testing
composer test
🔰 Version Support
| Larex | L5.8 | L6.x | L7.x | L8.x | L9.x | L10.x | L11.x | L12.x | L13.x |
|---|---|---|---|---|---|---|---|---|---|
| ^1.0 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ^1.2 | ^2.0 | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ^3.0 | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ^4.0 | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Larex | PHP7.2 | PHP7.3 | PHP7.4 | PHP8.0 | PHP8.1 | PHP8.2 | PHP8.3 | PHP8.4 | PHP8.5 |
|---|---|---|---|---|---|---|---|---|---|
| ^1.0 | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| ^1.6 | ^2.0 | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| ^3.0 | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
| ^4.0 | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
📃 Changelog
Please see the CHANGELOG.md for more information on what has changed recently.
🏅 Credits
📖 License
Please see the LICENSE.md file for more information.
lukasss93/laravel-larex 适用场景与选型建议
lukasss93/laravel-larex 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 96.94k 次下载、GitHub Stars 达 97, 最近一次更新时间为 2020 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「i18n」 「translation」 「csv」 「laravel」 「localization」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lukasss93/laravel-larex 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lukasss93/laravel-larex 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lukasss93/laravel-larex 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use i18n translation PHP class for multi-language websites
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
Yii2 integration for AirBnB Polyglot.js
统计信息
- 总下载量: 96.94k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 97
- 点击次数: 26
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-07-04