Download the PHP package mishalestev/laravel-files-translator without Composer
On this page you can find all versions of the php package mishalestev/laravel-files-translator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mishalestev/laravel-files-translator
More information about mishalestev/laravel-files-translator
Files in mishalestev/laravel-files-translator
Package laravel-files-translator
Short Description Extract translations from HTML/Blade files and generate translation files.
License MIT
Informations about the package laravel-files-translator
Laravel Files Translator
Files Translator for Laravel - is a package designed to streamline the process of extracting and translating text content from Blade or HTML files in your Laravel applications.
Installation
Run the following command in your Laravel project directory:
If you're unsure how this package works, please watch our short introductory video:
Under 10 minutes ✅ https://youtu.be/IsiUgIftRiw
Example Use Case
Suppose you have a file with the following text (that is the 4th commandement):
To translate this content into Spanish, run the following command:
This command will:
-
Generate a Translated Blade File:
It creates a new Blade file with the text replaced by__()
translation calls. This file uses unique keys mapped to text segments, due to maintenance considerations. - Produce Corresponding Translation Files:
It generates translation files within yourlang/
directory. You get both the source language and the target language files populated with key-value pairs, mapping each text snippet to its translation.
Resulting Files
Translated Blade File:
_resources/views/commandment_translated.blade.php
_
Translation Files:
lang/es/commandement.php
lang/en/commandement.php
Process In More Details
-
It Generates a Translated File:
After processing your specified input file (Blade or HTML), the package produces a new, translated file (_translated.blade.php
) in the same directory. This file has all the original plain text replaced by their translated equivalents. - Creates Corresponding Translation Files:
The package will generate language directories underlang/
for both the source language and the target language(s). Inside these directories, it will create translation files to store your translations. For example:
Example Usage
-
Create a New Laravel Project (if needed):
If you don't already have a Laravel project, create one using the following command: -
Run the Translation Command:
Use the Artisan command provided by the package to process and translate your Blade or HTML files.
For example:- Replace
es
with the desired target language code. - Specify the input file path and the output translation file path as required.
- Replace
-
Update Application Locale (Optional):
Openconfig/app.php
and modify the locale configuration as follows: -
Serve Your Application:
Run the Laravel development server to test the changes:Open your application in a browser to see the translations in action.
Artisan Command Signature
The package provides a customizable Artisan command:
Future Objectives & Roadmap
As we continue to develop and enhance the Laravel Files Translator package, here are several objectives and enhancements we plan to implement:
- Preserving Blade Directives:
Currently, the package removes all Blade directives. We aim to support the preservation of these directives in future releases, eliminating the need to manually re-insert them.
[!NOTE]
- ~File Replacement or New File Creation~ (Implemented)
We plan to introduce an option to replace the original file, akin to using a--force
flag in Git. This feature will complement the existing functionality that creates a new file with a_translated.blade.php
suffix.
-
Custom Output Directories:
Future versions may include a feature to specify a custom output directory (e.g.,built/
) for storing compiled files, translations, and Blade templates post-translation. This will let developers manually distribute files within a project (if applicable). -
Route-Based Language Switcher:
We're considering the addition of a feature to automatically set up a language switcher inroutes/web.php
, which will allow for quick testing and demonstration of different localizations. -
JSON Translation Support:
In addition to the default PHP array files, we plan to support the generation of JSON-based translation files, providing more flexibility in how translations are stored and used. -
Whitespace & Formatting Preservation:
Currently logic for handling spacing and indentation, particularly for nested elements, is needed. It has to retain space formatting of the translated files. -
Multiple Languages Support:
Builed a multiple language support (e.g.,--lang=en,es,fr
) in a single command, generating multiple sets of translated files simultaneously. -
Shortening Translation Keys:
We are looking for options to shorten the keys generated for translation entries, currently based on an MD5 algorithm, to make them more manageable. -
Handling Non-Native HTML Tags:
Plans include developing methods to recognize and correctly handle non-native HTML tags, which are currently not supported. -
Duplicate Text Optimization:
If the text is the same across the file, the system should reuse existing keys instead of generating new ones. - Community-Driven Features:
We actively encourage the community to contribute ideas and improvements. Please submit issues or pull requests on GitHub for any features you'd like to see incorporated or enhanced.
Your feedback and contributions help us make this tool better for everyone.
For More Information
If you have any questions or need support, feel free to reach out via email:
[email protected]
Credits
This project is built using the following open-source projects:
- Laravel – The foundation for building web applications.
- Stichoza\GoogleTranslate\GoogleTranslate – A robust tool for translating text.
Thanks for their outstanding work.
To Support
The greatest support you may offer is to read this book.
Whether you read it or not is your choise, and I respect it.
All versions of laravel-files-translator with dependencies
stichoza/google-translate-php Version ^4.0
laravel/framework Version ^8.0 || ^9.0 || ^10.0 || ^11.0
stillat/blade-parser Version ^1.10