This package serves the purpose of translating the contents within the spreadsheet file. It facilitates the transition from the original language to your preferred language
You can install the package via composer:
composer require shishima/laravel-translate-spreadsheet
php artisan vendor:publish --provider="Shishima\TranslateSpreadsheet\TranslateSpreadsheetServiceProvider"
After publishing the configuration file, you can edit the app/config/translate-spreadsheet.php file to customize the settings.
The file can be a path to a file on the system
use Shishima\TranslateSpreadsheet\Facades\TranslateSpreadsheet;
$fileInput = public_path('demo.xlsx');
TranslateSpreadsheet::translate($fileInput);
Or it could be a file retrieved from the request
when using the POST
method in a form submit
with <input type="file">
.
TranslateSpreadsheet::translate($request->file('file'));
To set the desired translation language target
TranslateSpreadsheet::setTransTarget('en')->translate($file);
To set the desired translation language source
TranslateSpreadsheet::setTransSource('en')->translate($file);
IMPORTANT! Pass in null
if you want to use language detection
Clear the current sheets after translation is complete. The parameter passed to the method is true/false
.
TranslateSpreadsheet::setShouldRemoveSheet(true)->translate($file);
Directory to store files after translation
TranslateSpreadsheet::setOutputDir('translate/')->translate($file);
IMPORTANT! The file will be stored in the public
directory, not in the storage
directory.
Position of the cloned sheets
The parameter passed in is enum ClonePosition
. You can refer to it in the file Enumerations/ClonePosition.php for more detail.
use Shishima\TranslateSpreadsheet\Enumerations\ClonePosition;
TranslateSpreadsheet::setCloneSheetPosition(ClonePosition::AppendLastSheet)->translate($file);
Sheets will be highlighted after export
TranslateSpreadsheet::highlightSheet(true)->translate($file);
Sheets Name will be translated after export
TranslateSpreadsheet::translateSheetName(true)->translate($file);
For logging translated sentences into a log file for debugging purposes
TranslateSpreadsheet::enableDebug()->translate($file);
To disable this feature, pass false
as the argument.
The package supports two translation engines: Google Translate and Gemini
It can be installed through the translate_engine
setting in the config file
Alternatively, you can use the setTranslateEngine function.
The parameter to be passed is an Enum TranslateEngine, which can be either TranslateEngine::Gemini
or TranslateEngine::Google
use Shishima\TranslateSpreadsheet\Enumerations\TranslateEngine;
TranslateSpreadsheet::setTranslateEngine(TranslateEngine::Gemini)->translate($file);
No need for setting
This functionality has been developed from google-gemini-php/laravel library
Therefore, please install this package before use
composer test
Utilize the repository below as a reference for how to use it.
https://github.com/shishima123/laravel-translate-spreadsheet-demo
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.