PHPackages                             amerhany/translation-service - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. amerhany/translation-service

ActiveLibrary[Localization &amp; i18n](/categories/localization)

amerhany/translation-service
============================

A Laravel package for translating text between supported languages.

v1.0.2(10mo ago)672MITPHPPHP ^7.4|^8.0|^8.1|^8.2|^8.3

Since Jan 15Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/amerhany/laravel-translation)[ Packagist](https://packagist.org/packages/amerhany/translation-service)[ Docs](https://github.com/amerhany/laravel-translation)[ RSS](/packages/amerhany-translation-service/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

Laravel Translation Service
===========================

[](#laravel-translation-service)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5583ccc0a5d9c8781fb1de98dc0ec28b90cc771c6160ed6ad4d65450f4503c2b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d657268616e792f7472616e736c6174696f6e2d736572766963652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amerhany/translation-service)[![Total Downloads](https://camo.githubusercontent.com/bd6b2fd039136f58b84ecfb5d75a10766e2f50705e1089e61c4873c4c2412e34/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d657268616e792f7472616e736c6174696f6e2d736572766963652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amerhany/translation-service)[![License](https://camo.githubusercontent.com/dce03f771a7b39245d4e898a4bc2cec03644214413566e8cae9a8d5d02ea2f6b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616d657268616e792f7472616e736c6174696f6e2d736572766963652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/amerhany/translation-service)

A Laravel package for translating text between supported languages using Google Translate. This package allows you to translate language files in bulk and supports queued jobs for efficient processing. It also provides functionality to track the progress of translation jobs, making it easy to display progress on the front end.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Translate Language Files](#translate-language-files)
    - [Run the Queue Worker](#run-the-queue-worker)
    - [Track Translation Progress](#track-translation-progress)
    - [Translate Single Text](#translate-single-text)
    - [Supported Languages](#supported-languages)
    - [Validate Language Codes](#validate-language-codes)
- [Contributing](#contributing)
- [License](#license)
- [Credits](#credits)

---

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require amir/translation-service
```

Publish Configuration:

```
php artisan vendor:publish --provider="Amir\TranslationService\Providers\TranslateServiceProvider"
```

Set Up Database Tables:

```
php artisan queue:table
php artisan queue:batches-table
php artisan migrate
```

Run the Install Command:

```
php artisan translation-service:install
```

---

Usage
-----

[](#usage)

After successfully installing the package, follow these steps to begin using it effectively

### Translate Language Files

[](#translate-language-files)

To translate a language file, use the `translateFile` method provided by the `TranslationService`.

```
use Amir\TranslationService\Services\TranslationService;

$filePath = base_path('resources/lang/en/messages.php');
$sourceLang = 'en';
$targetLang = 'es';

$response = TranslationService::translateFile($filePath, $sourceLang, $targetLang);

// Output the response
dd($response);
```

The **Response** will include the batch ID, which you can use to track the progress of the translation jobs:

```
[
    'code' => '200',
    'message' => 'Translation jobs dispatched',
    'batch_id' => 'batch-id-123', // Use this to track progress
    'start_time' => 1698765432, // Timestamp of when the batch started
]
```

### Run the Queue Worker

[](#run-the-queue-worker)

To process the translation jobs, you need to run the Laravel queue worker. Use the following command:

```
php artisan queue:work
```

### Track Translation Progress

[](#track-translation-progress)

You can track the progress of the translation jobs using the batch ID returned by the translateFile method. Laravel provides a Batch facade to query the status of a batch.

Here’s an example of how to track progress in your controller:

```
use Illuminate\Support\Facades\Bus;
use Illuminate\Support\Facades\Cache;

public function getBatchProgress($batchId)
{
    $batch = Bus::findBatch($batchId);

    if (!$batch) {
        return response()->json([
            'code' => '404',
            'message' => 'Batch not found',
        ], 404);
    }

    return response()->json([
        'code' => '200',
        'message' => 'Batch progress retrieved',
        'progress' => $batch->progress(),
        'total_jobs' => $batch->totalJobs,
        'pending_jobs' => $batch->pendingJobs,
        'failed_jobs' => $batch->failedJobs,
        'finished_at' => $batch->finishedAt,
    ]);
}
```

### Display Progress in HTML/JavaScript

[](#display-progress-in-htmljavascript)

To display the progress on the front end, you can poll the backend periodically using the batch ID. Here’s an example using HTML and JavaScript:

**HTML**

```

    Translation Progress: 0%
    Pending Jobs: 0
    Failed Jobs: 0
    Status: Processing...

```

**JavaScript**

```
async function trackProgress(batchId) {
    const response = await fetch(`/api/batch-progress/${batchId}`);
    const data = await response.json();

    if (data.code === '200') {
        // Update progress
        document.getElementById('progress').textContent = data.progress;
        document.getElementById('pending-jobs').textContent = data.pending_jobs;
        document.getElementById('failed-jobs').textContent = data.failed_jobs;

        if (data.progress === 100) {
            document.getElementById('status').textContent = 'Status: Completed!';
        } else {
            // Poll again after a delay
            setTimeout(() => trackProgress(batchId), 2000);
        }
    } else {
        console.error('Error tracking progress:', data.message);
    }
}

// Start tracking progress
const batchId = 'batch-id-123'; // Replace with your batch ID
trackProgress(batchId);
```

### Customizing the Front End

[](#customizing-the-front-end)

The example above provides a basic implementation for tracking and displaying translation progress. If you want to create your own front-end implementation, you can use the `getBatchProgress` API endpoint to fetch the progress data and display it in any way you prefer (e.g., using a progress bar, charts, or custom UI components).

Here’s the API response structure for reference:

```
{
    "code": "200",
    "message": "Batch progress retrieved",
    "progress": 50,
    "total_jobs": 100,
    "pending_jobs": 50,
    "failed_jobs": 0,
    "finished_at": null
}
```

You can use this data to build a more advanced or visually appealing progress tracker.

### Translate Single Text

[](#translate-single-text)

To translate a single text string, use the `translateText` method:

```
use Amir\TranslationService\Services\TranslationService;

$text = "Hello, world!";
$sourceLang = 'en';
$targetLang = 'es';

$translatedText = TranslationService::translateText($text, $sourceLang, $targetLang);

echo $translatedText; // Output: "¡Hola, mundo!"
```

### Supported Languages

[](#supported-languages)

The package supports a wide range of languages. You can retrieve the list of supported languages using the `getSupportedLanguages` method:

```
use Amir\TranslationService\Services\TranslationService;

$languages = TranslationService::getSupportedLanguages();
dd($languages);
```

### Validate Language Codes

[](#validate-language-codes)

Before translating text, you can validate whether a language code is supported using the `isLanguageSupported` method:

```
use Amir\TranslationService\Services\TranslationService;

$language = 'es';

if (TranslationService::isLanguageSupported($language)) {
    echo "The language '$language' is supported!";
} else {
    echo "The language '$language' is NOT supported.";
}
```

Contributing
------------

[](#contributing)

Contributions are welcome! If you'd like to contribute, please follow these steps:

- Fork the repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request.

Please ensure your code follows the PSR-12 coding standard and includes tests where applicable.

License
-------

[](#license)

This package is open-source software licensed under the MIT License.

Credits
-------

[](#credits)

[Amir Hany](https://github.com/amerhany)

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance54

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~86 days

Total

3

Last Release

309d ago

PHP version history (2 changes)v1.0.0PHP ^7.4|^8.0

v1.0.1PHP ^7.4|^8.0|^8.1|^8.2|^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/0175e60342de2f0d7ea889be6b8370c4b2979ccaaba6fa2c856ccc2bd4e64f97?d=identicon)[amerhany](/maintainers/amerhany)

---

Top Contributors

[![amerhany](https://avatars.githubusercontent.com/u/73230225?v=4)](https://github.com/amerhany "amerhany (14 commits)")

---

Tags

translation-serviceamer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/amerhany-translation-service/health.svg)

```
[![Health](https://phpackages.com/badges/amerhany-translation-service/health.svg)](https://phpackages.com/packages/amerhany-translation-service)
```

###  Alternatives

[barryvdh/laravel-translation-manager

Manage Laravel Translations

1.7k3.6M17](/packages/barryvdh-laravel-translation-manager)[vluzrmos/language-detector

Detect the language for your application using browser preferences, subdomains or route prefixes.

109554.8k3](/packages/vluzrmos-language-detector)[kerigard/laravel-lang-ru

Ru lang for Laravel

2116.8k](/packages/kerigard-laravel-lang-ru)[highsolutions/laravel-translation-manager

Manage Laravel Translations

1518.8k](/packages/highsolutions-laravel-translation-manager)[amendozaaguiar/laraveles-spanish-for-jetstream

Archivos de traducción al español latinoamericano para Laravel con Jetstream (auth, pagination, passwords, validation + todas las cadenas de Jetstream).

1412.1k](/packages/amendozaaguiar-laraveles-spanish-for-jetstream)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
