shishima/laravel-translate-spreadsheet

This package is used to translate spreadsheet files

v1.6 2024-03-15 03:33 UTC

This package is auto-updated.

Last update: 2024-11-15 04:59:25 UTC


README

Latest Version on Packagist Total Downloads

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

Installation

You can install the package via composer:

composer require shishima/laravel-translate-spreadsheet

Publish config

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.

Usage

translate

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'));

setTransTarget

To set the desired translation language target

TranslateSpreadsheet::setTransTarget('en')->translate($file);

setTransSource

To set the desired translation language source

TranslateSpreadsheet::setTransSource('en')->translate($file);

IMPORTANT! Pass in null if you want to use language detection

setShouldRemoveSheet

Clear the current sheets after translation is complete. The parameter passed to the method is true/false.

TranslateSpreadsheet::setShouldRemoveSheet(true)->translate($file);

setOutputDir

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.

setCloneSheetPosition

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);

highlightSheet

Sheets will be highlighted after export

TranslateSpreadsheet::highlightSheet(true)->translate($file);

translateSheetName

Sheets Name will be translated after export

TranslateSpreadsheet::translateSheetName(true)->translate($file);

enableDebug

For logging translated sentences into a log file for debugging purposes

TranslateSpreadsheet::enableDebug()->translate($file);

To disable this feature, pass false as the argument.

Translate Engine

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);

Google Translate

No need for setting

Gemini

This functionality has been developed from google-gemini-php/laravel library

Therefore, please install this package before use

Testing

composer test

Demo

Utilize the repository below as a reference for how to use it.

https://github.com/shishima123/laravel-translate-spreadsheet-demo

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email shishima21@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Laravel Package Boilerplate

This package was generated using the Laravel Package Boilerplate.

Special Thanks