PHPackages                             coding-partners/transla-genius - 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. [Database &amp; ORM](/categories/database)
4. /
5. coding-partners/transla-genius

ActiveLibrary[Database &amp; ORM](/categories/database)

coding-partners/transla-genius
==============================

A Laravel package for automatic translations.

v3.1.0(1y ago)1411MITPHPPHP &gt;=8.2

Since Mar 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/YousefSaleh1/transla-genius)[ Packagist](https://packagist.org/packages/coding-partners/transla-genius)[ RSS](/packages/coding-partners-transla-genius/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (6)Versions (9)Used By (0)

TranslaGenius Package
=====================

[](#translagenius-package)

The TranslaGenius package is a Laravel package designed to automatically translate fields in your Eloquent models using an external translation API. It supports multiple languages and provides flexible translation management.

Features
--------

[](#features)

- Multi-language support (configurable)
- Automatic field translation
- Queue-based translation processing
- Flexible API integration
- Comprehensive scope filters

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

[](#installation)

To install the package, you can use Composer:

```
composer require coding-partners/transla-genius
```

Configuration
-------------

[](#configuration)

After installing the package, you need to publish the configuration file:

```
php artisan vendor:publish --provider="CodingPartners\TranslaGenius\TranslaGeniusServiceProvider" --tag="translagenius-config"
```

This will create a `translaGenius.php` file in your `config` directory. You can modify this file to set your Supported Languages, and other translation settings:

```
return [
    /*
    |--------------------------------------------------------------------------
    | Supported Languages
    |--------------------------------------------------------------------------
    | List of supported language codes (ISO 639-1).
    | The first language will be considered as default.
    */
    'supported_languages' => ['en', 'ar', 'es', 'fr'],

    // ... other settings
];
```

### Environment Variables

[](#environment-variables)

Make sure to set the following environment variables in your `.env` file:

```
TRANSLATION_API_KEY=your_openai_api_key
TRANSLATION_API_URL=https://openrouter.ai/api/v1/chat/completions
TRANSLATION_MODEL=openai/gpt-4o
TRANSLATION_TEMPERATURE=0.3
TRANSLATION_MAX_TOKENS=200
```

Usage
-----

[](#usage)

### Step 1: Include the `Translatable` Trait in Your Model

[](#step-1-include-the-translatable-trait-in-your-model)

To enable automatic translation for your model, include the `Translatable` trait in your Eloquent model:

```
use CodingPartners\TranslaGenius\Traits\Translatable;

class Post extends Model
{
    use Translatable;

    // Define the fields that should be translated
    public $translatable = [
        'title',
        'content',
    ];
}
```

### Step 2: Update Your Migration

[](#step-2-update-your-migration)

Ensure that the fields you want to translate are of type `json` in your migration:

```
Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->json('title');
    $table->json('content');
    $table->timestamps();
});
```

### Step 3: Middleware Setup

[](#step-3-middleware-setup)

To automatically set the locale based on the request, you can include the `SetLocale` middleware in your `bootstrap/app.php`:

```
use CodingPartners\TranslaGenius\Middleware\SetLocale;

->withMiddleware(function (Middleware $middleware) {

    $middleware->api(prepend: [

        SetLocale::class,

    ]);

})
```

### Step 4: Making Requests

[](#step-4-making-requests)

When making requests to your application, you can set the `Accept-Language` header to specify the desired language:

```
curl -X GET http://yourapp.com/api/posts -H "Accept-Language: en"
```

This will set the locale to English (`en`), which means the default language of the system is now English. When you add a new record, you should send the fields in English, and the package will automatically translate them into Arabic.

### Step 5: Running the Queue

[](#step-5-running-the-queue)

The translation process is handled by a job that is dispatched when a model is created or updated. To ensure that the translations are processed, you need to run the queue worker:

```
php artisan queue:work
```

This will process the `TranslateFields` job and perform the translations in the background.

### Example of Using the `fullyTranslated` Scope

[](#example-of-using-the-fullytranslated-scope)

The `Translatable` trait provides a `fullyTranslated` scope that allows you to filter models that are fully translated in the Supported Languages.

```
$posts = Post::fullyTranslated()->get();
```

This scope checks if all translatable fields have a translation in the Supported Languages. It ensures that only records with complete translations are returned, which is useful for ensuring data consistency and completeness.

How It Works
------------

[](#how-it-works)

1. **Model Events**: When a model is created or updated, the `Translatable` trait automatically dispatches a `TranslateFields` job.
2. **Translation Job**: The `TranslateFields` job uses the `AutoTranslationService` to translate the specified fields into the target language.
3. **Translation Service**: The `AutoTranslationService` communicates with the external API to perform the translation and updates the model with the translated content.

Example Workflow
----------------

[](#example-workflow)

Here’s a complete example of how to use the package:

### Model

[](#model)

```
use CodingPartners\TranslaGenius\Traits\Translatable;

class Product extends Model
{
    use Translatable;

    protected $fillable = [
        'price',
        'name',
        'description'
    ];

    public $translatable = [
        'name',
        'description'
    ];
}
```

### Migration

[](#migration)

```
Schema::create('products', function (Blueprint $table) {
    $table->id();
    $table->decimal('price');
    $table->json('name');
    $table->json('description');
    $table->timestamps();
});
```

### Controller

[](#controller)

```
public function store(Request $request)
{
    $product = Product::create([
        'price' => $request->price,
        'name' => $request->name,
        'description' => $request->description
    ]);

    return response()->json([
        "data" => $product,
        "message" => "Done!!"
    ], 201);
}
```

### Request

[](#request)

```
curl -X POST http://yourapp.com/api/posts -H "Accept-Language: en" -d '{"name": "name in English", "description": "description in English", "price": 100}'
```

After the request, the `name` and `description` fields will be automatically translated into Supported Languages.

Troubleshooting
---------------

[](#troubleshooting)

### Common Issues

[](#common-issues)

#### Missing translations:

[](#missing-translations)

- Verify queue worker is running
- Check API credentials
- Confirm language codes match config

#### Performance:

[](#performance)

- Add indexes to JSON columns
- Consider caching frequent translations

Conclusion
----------

[](#conclusion)

The TranslaGenius package simplifies the process of adding multi-language support to your Laravel application. By following the steps outlined above, you can easily configure and use the package to automatically translate your model fields, ensuring that your application is accessible to a global audience.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance50

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95% 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 ~7 days

Total

8

Last Release

367d ago

Major Versions

1.0.0 → 2.0.02025-03-26

2.2.1 → 3.0.02025-04-26

### Community

Maintainers

![](https://www.gravatar.com/avatar/2e84e68f370016f55e9b845f2a737265c50a5190bbc505c6fb8ab3e3a06cbeb5?d=identicon)[YousefSaleh](/maintainers/YousefSaleh)

---

Top Contributors

[![YousefSaleh1](https://avatars.githubusercontent.com/u/148710592?v=4)](https://github.com/YousefSaleh1 "YousefSaleh1 (19 commits)")[![somarkn99](https://avatars.githubusercontent.com/u/44697004?v=4)](https://github.com/somarkn99 "somarkn99 (1 commits)")

---

Tags

middlewarelaravellocalizationautomationi18ntranslationeloquentmultilingualqueueopenaijobsgptOpenRoutertranslation-managerspatie-translatableai translationjson translationsauto-translation

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/coding-partners-transla-genius/health.svg)

```
[![Health](https://phpackages.com/badges/coding-partners-transla-genius/health.svg)](https://phpackages.com/packages/coding-partners-transla-genius)
```

###  Alternatives

[richan-fongdasen/laravel-i18n

Simple route and eloquent localization / translation in Laravel

1296.6k](/packages/richan-fongdasen-laravel-i18n)[io238/laravel-iso-countries

Ready-to-use Laravel models and relations for country (ISO 3166), language (ISO 639-1), and currency (ISO 4217) information with multi-language support.

5462.3k](/packages/io238-laravel-iso-countries)[jayesh/laravel-gemini-translator

An interactive command to extract and generate Laravel translations using Gemini AI.

691.7k1](/packages/jayesh-laravel-gemini-translator)[omaralalwi/lexi-translate

Laravel translation package with morph relationships and caching.

754.3k2](/packages/omaralalwi-lexi-translate)

PHPackages © 2026

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