Artisan 命令可自动生成和更新 lang 文件
LLH is a set of artisan commands to manage translations in your Laravel project. Key features :
| Laravel | Lumen | Package |
|---|---|---|
| 4.2.x | 2.0.x (EOL last version is 2.0.4) | |
| 5.0.x | 2.1.x | |
| 5.1.x | 5.1.x | 2.2.x |
| 5.2.x | 5.2.x | 2.3.x |
| 5.3.x | 5.3.x | 2.4.x |
| 5.4.x | 5.4.x | 2.5.x |
| 5.5.x | 5.5.x | 2.6.x |
Add the following line in the require-dev array of the composer.json file and replace the version if needed according to your Laravel version:
"potsky/laravel-localization-helpers" : "2.6.*"Update your installation : composer update
For Laravel, add the following lines in the AppServiceProvider array of the config/app.php configuration file :
Potsky\LaravelLocalizationHelpers\LaravelLocalizationHelpersServiceProvider::class, On Laravel 5.5, if you don't use the package in production, disable auto-loading and register it only on local or dev:
Add the following lines in the register method of the AppServiceProvider :
public function register()
{
if ($this->app->environment() === 'dev') { // or local or whatever
$this->app->register(\Potsky\LaravelLocalizationHelpers\LaravelLocalizationHelpersServiceProvider::class);
}
}Disable to auto-register provider by adding these lines in the composer.json file:
"extra" : {
"laravel" : {
"dont-discover" : [
"potsky/laravel-localization-helpers"
]
}
}For Lumen, add the following lines in the bootstrap/app.php file :
$app->register( Potsky\LaravelLocalizationHelpers\LaravelLocalizationHelpersServiceProvider::class );
$app->configure('laravel-localization-helpers');Now execute php artisan list and 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' => Potsky\LaravelLocalizationHelpers\Facade\LocalizationHelpers::classTo configure your fresh installed package, please create a configuration file by executing :
php artisan vendor:publishThen you can modify the configuration in file :
config/laravel-localization-helpers.phpAdd new folders to search for, add your own lang methods or functions, ...
For Lumen, copy manually the configuration file as
config/laravel-localization-helpers.php.
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].phplocalization:missingThis 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.
php artisan localization:missingphp artisan localization:missing -nphp artisan localization:missing -bphp artisan localization:missing -tYou need to set your Microsoft Bing Translator credentials More informations here :
php artisan localization:missing -ophp artisan localization:missing -cphp artisan localization:missing -d3 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 nullThe following command set all lemma values to "Please translate this !"
php artisan localization:missing -l 'Please translate this !'#!/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"
fiphp artisan localization:missing -rphp artisan localization:missing -eYou 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'localization:findThis command will search in all your code for the argument as a lemma.
Use php artisan help localization:find for more informations about options.
php artisan localization:find Searchphp artisan localization:find -v Searchphp artisan localization:find -s "Search me"php artisan localization:find -s -r "@Search.*@"
php artisan localization:find -s -r "/.*me$/"PCRE functions are used
localization:clearThis command will remove all backup lang files.
Use php artisan help localization:clear for more informations about options.
php artisan localization:clearphp artisan localization:clear -d 7Use the github issue tool to open an issue or ask for something.
v2.x.5 to v2.x.6v2.x.4 to v2.x.5dot_notation_split_regex has been added in the configuration file. Add it in your configuration file.v2.x.1 to v2.x.2obsolete_array_key has been added in the configuration file. Add it in your configuration file.v1.x.x to v2.x.xdot_notation_split_regex has been added to automatically handle dots in lemma (#59)2.4.4 branch (#41)friendsofphp/php-cs-fixer instead of fabpot/php-cs-fixer (#28)localization:clear to remove backupsTODO: prefix by default (if you ran two times the missing artisan command without translating lemma next to the first run, your missing translation were lost in the lang file. Now by default, just search for TODO in your lang file!)t is usedtrans( 'message.child.this is a text' ) will now generate ['child'] => 'TODO: this is a text',暂无开放 Issues,或尚未同步最近议题。