TransLaravelizer is a Python utility designed to streamline the process of localizing Laravel applications. It automates the extraction of texts wrapped within trans() functions from Blade templates and generates language JSON files, facilitating a smoother translation workflow.
- Automatically scans Blade templates for
trans()calls. - Efficiently extracts text strings and organizes them into JSON format.
- Initializes language files for English and Arabic, with easy extension to other languages.
- Adaptable to various Laravel project structures.
- Python 3.8 or later.
- A Laravel project with Blade templates utilizing the
trans()function for translations.
Clone this repository into your project's root directory:
git clone https://github.com/aymansy93/TransLaravelizer.git-
Run the script by executing the following command:
python lang.py
This command will extract all the translatable strings from your Blade templates and controller files and write them to JSON files located in the
langExportdirectory.
Note: Set this script in the resources folder of your Laravel project to ensure it can access the necessary Blade and controller files.
-
Change Search Directories: If your Blade templates or controllers are in different directories, update the
search_directoriesdictionary in the script:search_directories = { 'blade': 'path/to/your/views', 'controller': 'path/to/your/controllers' }
-
Add More Languages: To generate additional language files, modify the
lang_fileslist:lang_files = ['en.json', 'ar.json', 'es.json']
After running the script, the langExport directory will contain JSON files with the extracted translatable strings, formatted for easy localization.
- The script uses the
trans()function to identify translatable strings. If you use a different function or need to support additional patterns, you may need to modify the regex pattern in the script. - Make sure your project files are encoded in UTF-8 to avoid encoding issues.
- Ensure you have write permissions for the
langExportdirectory.
Feel free to fork this project, make improvements, and submit pull requests. Suggestions are welcome!
This project is licensed under the MIT License - see the LICENSE.md file for details.