
Localization - Automatically Generate Translation JSON Files
In this article we will discuss how to automatically generate translation JSON files in laravel 11.We will use `devaslanphp/auto-translate ` laravel package .This package generate JSON files using Google Translator and exports translations string from your source code.This package is the wrapper of two packages ( stichoza/google-translate-php , kkomelin/laravel-translatable-string-exporter ).
Localization is essential for reaching a global audience.Creating and updating translation files by hand can be slow and mistakes can happen easily. Automating this task saves your time and ensures that all translations in your app are consistent.
For more detailed information and to view the source code, visit GitHub repository
Installation and Setup
First you need install the spatie laravel package tool
Install the package using composer
After you successfully install, add the package provider into Bootstrap > providers.php
REQUIRED : You must publish the package's configuration file to modify the base_locale and the list of locales as needed:
config > auto-translate.php
Usage
To generate translation JSON files, run this command:
This command will check your auto-translate.locales form config file and generate JSON files based on your source code.This package supports both syntax @lang() and __() .
The package also offers a command to generate translations for missing keys based on a specific JSON file (auto-translate.base_locale.json).
Generating JSON Files for Translation
Once everything is set up, you can start generating the translation content.


