keypoint-solutions/laravel-localization-helpers
Composer 安装命令:
composer require keypoint-solutions/laravel-localization-helpers
包简介
An artisan command package and methods for easy translation management. Derived from potsky's repo, adding modern PHP &Laravel support, updated MS translator support and other features
README 文档
README
This branch is the current dev branch
LLH is a set of artisan commands to manage translations in your Laravel project. Key features :
- parse your code and generate lang files
- translate your sentences automatically, thanks to Microsoft Translator API
- configure output according to your code style
Table of contents
1. Installation
- Choose your version according to the version compatibility matrix:
| Laravel | Lumen | Package |
|---|---|---|
| 8.x - 12.x | 8.x - 12.x | main |
-
Add the following line in the
require-devarray of thecomposer.jsonfile and replace the version if needed according to your Laravel version:"keypoint-solutions/laravel-localization-helpers" : "^7.2"
-
Update your installation :
composer update -
For Laravel, add the following line in the
providersarray of theconfig/app.phpconfiguration file :\LaravelLocalizationHelpersServiceProvider::class,
-
For Lumen, add the following lines in the
bootstrap/app.phpfile :$app->register( \LaravelLocalizationHelpersServiceProvider::class ); $app->configure('laravel-localization-helpers');
-
Now execute
php artisan listand you should view the new localization commands:... localization localization:clear Remove lang backup files localization:find Display all files where the argument is used as a lemma localization:missing Parse all translations in app directory and build all lang files ...
In Laravel, you can add the facade in the Aliases if you need to manage translations in your code :
'LocalizationHelpers' => Facade\LocalizationHelpers::class
2. Configuration
To configure your fresh installed package, please create a configuration file by executing :
php artisan vendor:publish
Then you can modify the configuration in file :
config/laravel-localization-helpers.php
Add new folders to search for, add your own lang methods or functions, ...
Backup files
You should not include backup lang files in GIT or other versioning systems.
In your laravel folder, add this in .gitignore file :
# Do not include backup lang files resources/lang/*/[a-zA-Z]*20[0-9][0-9][0-1][0-9][0-3][0-9]_[0-2][0-9][0-5][0-9][0-5][0-9].php
3. Usage
3.1 Command localization:missing
This command parses all your code and generates translations according to lang files in all lang/XXX/ directories.
Use php artisan help localization:missing for more informations about options.
Examples
Generate all lang files
php artisan localization:missing
Generate all lang files without prompt
php artisan localization:missing -n
Generate all lang files without backuping old files
php artisan localization:missing -b
Generate all lang files with automatic translations
php artisan localization:missing -t
Generate all lang files without keeping obsolete lemmas
php artisan localization:missing -o
Generate all lang files without any comment for new found lemmas
php artisan localization:missing -c
Generate all lang files without header comment
php artisan localization:missing -d
Generate all lang files and set new lemma values
3 commands below produce the same output:
php artisan localization:missing
php artisan localization:missing -l
php artisan localization:missing -l "TODO: %LEMMA"
You can customize the default generated values for unknown lemmas.
The following command let new values empty:
php artisan localization:missing -l ""
The following command prefixes all lemma values with "Please translate this : "
php artisan localization:missing -l "Please translate this : %LEMMA"
The following command set all lemma values to null to provide fallback translations to all missing values.
php artisan localization:missing -l null
The following command set all lemma values to "Please translate this !"
php artisan localization:missing -l 'Please translate this !'
Silent option for shell integration
#!/bin/bash php artisan localization:missing -s if [ $? -eq 0 ]; then echo "Nothing to do dude, GO for release" else echo "I will not release in production, lang files are not clean" fi
Simulate all operations (do not write anything) with a dry run
php artisan localization:missing -r
Open all must-edit files at the end of the process
php artisan localization:missing -e
You can edit the editor path in your configuration file. By default, editor is Sublime Text on Mac OS X :
'editor_command_line' => '/Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl'
For PHPStorm on Mac OS X:
'editor_command_line' => '/usr/local/bin/phpstorm'
3.2 Command localization:find
This command will search in all your code for the argument as a lemma.
Use php artisan help localization:find for more informations about options.
Examples
Find regular lemma
php artisan localization:find Search
Find regular lemma with verbose
php artisan localization:find -v Search
Find regular lemma with short path displayed
php artisan localization:find -s "Search me"
Find lemma with a regular expression
php artisan localization:find -s -r "@Search.*@" php artisan localization:find -s -r "/.*me$/"
PCRE functions are used
3.3 Command localization:clear
This command will remove all backup lang files.
Use php artisan help localization:clear for more informations about options.
Examples
Remove all backups
php artisan localization:clear
Remove backups older than 7 days
php artisan localization:clear -d 7
4. Support
Use the github issue tool to open an issue or ask for something.
5. Contribute
- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Added some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request
keypoint-solutions/laravel-localization-helpers 适用场景与选型建议
keypoint-solutions/laravel-localization-helpers 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 228 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 keypoint-solutions/laravel-localization-helpers 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 keypoint-solutions/laravel-localization-helpers 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 228
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2024-04-07