An artisan command package for easy translation management
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:
Add the following line in the
require-devarray of the
composer.jsonfile and replace the version if needed according to your Laravel version:
"potsky/laravel-localization-helpers" : "2.3.*"
Update your installation :
Add the following line in the
providersarray of the
config/app.phpconfiguration file :
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 ...
You can add the facade in the Aliases if you need to manage translations in your code :
'LocalizationHelpers' => 'Potsky\LaravelLocalizationHelpers\Facade\LocalizationHelpers'
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 :
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.
laravel folder, add this in
.gitignore file :
# Do not include backup lang files app/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
php artisan help localization:missing for more informations about options.
php artisan localization:missingGenerate all lang files without prompt
php artisan localization:missing -nGenerate all lang files without backuping old files
php artisan localization:missing -bGenerate all lang files with automatic translations
php artisan localization:missing -t
Generate all lang files without keeping obsolete lemmas
You need to set your Microsoft Bing Translator credentials More informations here : https://github.com/potsky/microsoft-translator-php-sdk#user-content-2-configuration
php artisan localization:missing -oGenerate all lang files without any comment for new found lemmas
php artisan localization:missing -cGenerate all lang files without header comment
php artisan localization:missing -dGenerate 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 "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" fiSimulate all operations (do not write anything) with a dry run
php artisan localization:missing -rOpen 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'
This command will search in all your code for the argument as a lemma.
php artisan help localization:find for more informations about options.
php artisan localization:find SearchFind regular lemma with verbose
php artisan localization:find -v SearchFind 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
This command will remove all backup lang files.
php artisan help localization:clear for more informations about options.
php artisan localization:clearRemove backups older than 7 days
php artisan localization:clear -d 7
Use the github issue tool to open an issue or ask for something.
obsolete_array_keyhas been added in the configuration file. Add it in your configuration file.
- First you need to update your composer file to set the correct version
- Take a look at the configuration file in the package to add new parameters you don't have in your current package configuration file.
- fix a bug when using backup files and when a dot is in your laravel installation path (#20)
- new command
localization:clearto remove backups
- new option to specify output formatting (#17)
- new option to specify flat arrays style output (#18)
- new option to let the command translate sentences for you with Bing Translator
- new translations are now:
- marked with the
TODO: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!)
- translated of course if option
- shorten to their minimal value (
trans( 'message.child.this is a text' )will now generate
['child'] => 'TODO: this is a text',and no more
['child'] => 'TODO: child.this is a text',)
- marked with the
- totally refactored
- unit tests
- test coverage
- facade to let you use localization helpers in your code (translations, find missing translations, etc...)
- End of life. Version 1.x is no more supported and no longer works. Please use the correct version according to your laravel version.
- fix incompatibility with Laravel 5.2 (#16)
- add resource folder for Laravel 5
- add full support for Laravel 5
- add support for @lang and @choice in Blade templates (by Jesper Ekstrand)
lang_folder_pathparameter in configuration file to configure the custom location of your lang files
- check lang files in
app/langby default for Laravel 4.x
- check lang files in
app/resources/langby default for Laravel 5
- support for Laravel 5 (4.3)
ignore_lang_filesparameter in configuration file to ignore lang files (useful for
validationfile for example)
- 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
Tests are in
tests. To run the tests:
Coverage cannot decrease next a merge. To track file coverage, run
vendor/bin/phpunit --coverage-html coverage and open
coverage/index.html to check uncovered lines of code.