|
| 1 | +# Auto Translate |
| 2 | + |
| 3 | +[](https://packagist.org/packages/devaslanphp/auto-translate) |
| 4 | +[](https://packagist.org/packages/devaslanphp/auto-translate) |
| 5 | + |
| 6 | +This package provides a simple way to automatically generate translation JSON files for you, it helps you to generate the missing translation also. |
| 7 | +The translation are generated automatically using Google Translations, based on the package `stichoza/google-translate-php` and exporting translations string from your source code using the package `kkomelin/laravel-translatable-string-exporter`. |
| 8 | + |
| 9 | +# Installation |
| 10 | + |
| 11 | +You can install the package via composer: |
| 12 | + |
| 13 | +```shell |
| 14 | +composer require devaslanphp/auto-translate |
| 15 | +``` |
| 16 | + |
| 17 | +*REQUIRED*: You need to publish the package config file, so you can update the `base_locale` and `locales` list as needed: |
| 18 | + |
| 19 | +```shell |
| 20 | +php artisan vendor:publish --tag=auto-translate |
| 21 | +``` |
| 22 | + |
| 23 | +**That's it**, you can use the package commands to generate missing translations and automatically translate them using Google Translations |
| 24 | + |
| 25 | +# Configuration |
| 26 | + |
| 27 | +The configuration file of this package comes like below: |
| 28 | + |
| 29 | +```php |
| 30 | +<?php |
| 31 | + |
| 32 | +return [ |
| 33 | + |
| 34 | + /* |
| 35 | + * |
| 36 | + * Locales managed by auto-translation package, will be used by the |
| 37 | + * command "auto:translate" to generate a JSON file for each of this |
| 38 | + * locales, and by the command "translate:missing" to generate their |
| 39 | + * missing translations |
| 40 | + * |
| 41 | + */ |
| 42 | + 'locales' => [ |
| 43 | + 'fr', |
| 44 | + 'ar' |
| 45 | + ], |
| 46 | + |
| 47 | + /* |
| 48 | + * |
| 49 | + * The base locale to use when using the command "translate:missing" to |
| 50 | + * generate missing translations for other JSON files |
| 51 | + * |
| 52 | + */ |
| 53 | + 'base_locale' => 'fr' |
| 54 | + |
| 55 | +]; |
| 56 | +``` |
| 57 | + |
| 58 | +I think it's well documented, I will let you check it. |
| 59 | + |
| 60 | +## Usage |
| 61 | + |
| 62 | +The package provides 2 Artisan commands: |
| 63 | + |
| 64 | +### Automatic translations generation |
| 65 | + |
| 66 | +To generate translation JSON files from your source code, you can execute the following command: |
| 67 | + |
| 68 | +```shell |
| 69 | +php artisan auto:translate |
| 70 | +``` |
| 71 | + |
| 72 | +This command will check your configuration `auto-translate.locales` to generate for each locale of this list a JSON file based on your source code (`@lang()`, `__()`, ...) and translate the string into the desired locale based on Google Translations. |
| 73 | + |
| 74 | +### Translate missing keys |
| 75 | + |
| 76 | +The package provides also a command to let you generate translations for missing keys based on a specific JSON file (`auto-translate.base_locale`.json). To generate missing translation, you only need to execute the following command: |
| 77 | + |
| 78 | +```shell |
| 79 | +php artisan translate:missing |
| 80 | +``` |
| 81 | + |
| 82 | +## Credits |
| 83 | + |
| 84 | +- [All Contributors](https://github.com/devaslanphp/auto-translate/graphs/contributors) |
| 85 | + |
| 86 | +## License |
| 87 | + |
| 88 | +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
0 commit comments