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
- Choose your version according to the version compatibility matrix:
Laravel | Lumen | Package |
---|---|---|
8.0.x | 8.0.x | main |
9.0.x | 9.0.x | main |
-
Add the following line in the
require-dev
array of thecomposer.json
file and replace the version if needed according to your Laravel version:"keypoint-solutions/laravel-localization-helpers" : "3.0.*"
-
Update your installation :
composer update
-
For Laravel, add the following line in the
providers
array of theconfig/app.php
configuration file :\LaravelLocalizationHelpersServiceProvider::class,
-
For Lumen, add the following lines in the
bootstrap/app.php
file :$app->register( \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' => Facade\LocalizationHelpers::class
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, ...
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
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.
php artisan localization:missing
php artisan localization:missing -n
php artisan localization:missing -b
php artisan localization:missing -t
php artisan localization:missing -o
php artisan localization:missing -c
php artisan localization:missing -d
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 !'
#!/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
php artisan localization:missing -r
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'
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.
php artisan localization:find Search
php artisan localization:find -v Search
php artisan localization:find -s "Search me"
php artisan localization:find -s -r "@Search.*@"
php artisan localization:find -s -r "/.*me$/"
PCRE functions are used
This command will remove all backup lang files.
Use php artisan help localization:clear
for more informations about options.
php artisan localization:clear
php artisan localization:clear -d 7
Use the github issue tool to open an issue or ask for something.
- 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