Awesome
Automatically translate your lang files
This package translates your Laravel localization files automatically using a third party service. Currently only supports DeepL.
This package only works with 'Short Keys' approach
Installation
You can install the package via composer:
composer require --dev javidalpe/laravel-localization-automation
If you're on Laravel 5.4 or earlier, you'll need to add the following to your config/app.php:
'providers' => [
...
Javidalpe\LaravelLocalizationAutomation\LaravelLocalizationAutomationServiceProvider::class,
];
Usage
This command translates all your files in /lang/{from}/
directory and create the new ones in /lang/{to}/
directory.
php artisan localization:translate {from} {to} {--provider=deepl}
Example using default provider:
php artisan localization:translate es fr
Example using custom provider:
php artisan localization:translate es fr --provider=deepl
Known issues
The command will fail on:
- Lemmas with HTML inside.
\\Wrong 'welcome.greetings' => '<strong>Hey!</strong>', \\Good 'welcome.greetings' => 'Hey!',
- Lemmas with placeholders different from Laravel.
\\Wrong 'welcome.greetings' => 'Hey {{name}}!', \\Good 'welcome.greetings' => 'Hey!',
- URLs. Fix these URLs manually.
Supported Languages
Deeply
DeepL(y) supports these languages:
Code | Language |
---|---|
DE | German |
EN | English |
FR | French |
ES | Spanish |
IT | Italian |
NL | Dutch |
PL | Polish |
DeepL says they will add more languages in the future, such as Chinese and Russian.
How it works
- Foreach file in
/lang/{from}/
directory. - Foreach lemma in file.
- Split pluralization lemmas.
- Replace each Laravel place-holder with temp string.
- Translate the lemma using the provider.
- Undo replacement.
- Assembly all lemmas in new files at
/lang/{to}/
directory.
Contributing
- Fork it
- Create your feature branch (git checkout -b my-new-translation-service)
- Commit your changes (git commit -am 'Added translation service')
- Push to the branch (git push origin my-new-translation-service)
- Create new Pull Request
Add a new translation service
- Create a new class inside
/src/TranslationServices
. ImplementsTranslationServiceStrategy
. - Add this class to
TranslationServiceStrategyFactory
. - Update this `README.md file.
Credits
- DeepL GmbH: https://www.deepl.com/
- Chris Konnertz: https://github.com/chriskonnertz/DeepLy
License
The MIT License (MIT). Please see License File for more information.