PHPackages                             bambolee-digital/translatable-resource-kit - 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. bambolee-digital/translatable-resource-kit

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

bambolee-digital/translatable-resource-kit
==========================================

Enhanced translation capabilities for Laravel models with dynamic JSON handling, optimized for app development

1.0.6(1y ago)3301MITPHPPHP ^8.0

Since Sep 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Bambolee-Digital/translatable-resource-kit)[ Packagist](https://packagist.org/packages/bambolee-digital/translatable-resource-kit)[ RSS](/packages/bambolee-digital-translatable-resource-kit/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (4)Versions (8)Used By (1)

Bambolee Translatable Resource Kit
==================================

[](#bambolee-translatable-resource-kit)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b0346d26ff3db7d45eabe15f2d77b1297851ce40786794e19f6fe625b5574177/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62616d626f6c65652d6469676974616c2f7472616e736c617461626c652d7265736f757263652d6b69742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bambolee-digital/translatable-resource-kit)[![Total Downloads](https://camo.githubusercontent.com/6b148c83e3d027964aafc23596e93605a39d61da413702b8ccd83993639ebebc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62616d626f6c65652d6469676974616c2f7472616e736c617461626c652d7265736f757263652d6b69742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bambolee-digital/translatable-resource-kit)[![License](https://camo.githubusercontent.com/970a70467daa52f05079260c6b2c6efba642ea530d7f0a21f31c3c5c1ff20843/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f62616d626f6c65652d6469676974616c2f7472616e736c617461626c652d7265736f757263652d6b69742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/bambolee-digital/translatable-resource-kit)

The Bambolee Translatable Resource Kit is a powerful extension for Laravel applications using Spatie's Laravel Translatable package. It simplifies the handling of translated attributes in API responses and dynamic JSON structures, making it easier to develop multilingual applications.

Features
--------

[](#features)

- Seamless integration with Spatie's Laravel Translatable
- Dynamic handling of translated attributes in JSON responses
- Support for nested relations and deep translation
- Customizable recursion depth for nested translations
- Easy-to-use Resource and Collection classes for API responses
- Compatible with Laravel 8.x, 9.x, 10.x, and 11.x

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

[](#installation)

You can install the package via composer:

```
composer require bambolee-digital/translatable-resource-kit
```

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

[](#configuration)

After installation, publish the configuration file:

```
php artisan vendor:publish --provider="BamboleeDigital\TranslatableResourceKit\TranslatableResourceKitServiceProvider" --tag="config"
```

This will create a `config/translatable-resource-kit.php` file where you can customize the behavior of the package.

You can customize the middleware behavior in this configuration file:

```
return [
    // disable debug
    'debug' => false,
    // Disable automatic middleware registration
    'disable_middleware' => false,
    // Specify the middleware group (default is 'api')
    'middleware_group' => 'api',
    // ... other configurations
];
```

### Added set\_locale

[](#added-set_locale)

To apply the SetLocale middleware to your API routes, you can add it to your `routes/api.php` file. Here's a comprehensive example of how to do this:

```
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\API\ProductController;
use App\Http\Controllers\API\CategoryController;

Route::middleware(['set_locale', SetLocale::class])->group(function () {
    // Product routes
    Route::prefix('products')->group(function () {
        Route::get('/', [ProductController::class, 'index']);
        Route::get('/{product}', [ProductController::class, 'show']);
        Route::post('/', [ProductController::class, 'store']);
        Route::put('/{product}', [ProductController::class, 'update']);
        Route::delete('/{product}', [ProductController::class, 'destroy']);
    });

    // Category routes
    Route::prefix('categories')->group(function () {
        Route::get('/', [CategoryController::class, 'index']);
        Route::get('/{category}', [CategoryController::class, 'show']);
        Route::post('/', [CategoryController::class, 'store']);
        Route::put('/{category}', [CategoryController::class, 'update']);
        Route::delete('/{category}', [CategoryController::class, 'destroy']);
    });

    // Add more route groups as needed
});
```

1. Open your `routes/api.php` file.
2. Add the middleware to your API route group like this:

### Disabling the Middleware

[](#disabling-the-middleware)

If you want to disable the automatic registration of the middleware, set the `disable_middleware` option to `true` in your configuration file.

Usage
-----

[](#usage)

### 1. Use the TranslatesAttributes trait in your model:

[](#1-use-the-translatesattributes-trait-in-your-model)

```
use BamboleeDigital\TranslatableResourceKit\Http\Traits\TranslatesAttributes;
use Spatie\Translatable\HasTranslations;

class Product extends Model
{
    use HasTranslations, TranslatesAttributes;

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

    // ...
}
```

### 2. Create a Resource for your model:

[](#2-create-a-resource-for-your-model)

```
use BamboleeDigital\TranslatableResourceKit\Http\Resources\TranslatableResource;

class ProductResource extends TranslatableResource
{
    // You can add custom logic here if needed
}
```

### 3. Create a Collection for your model:

[](#3-create-a-collection-for-your-model)

```
use BamboleeDigital\TranslatableResourceKit\Http\Resources\TranslatableCollection;

class ProductCollection extends TranslatableCollection
{
    // You can add custom logic here if needed
}
```

### 4. Use in your controller:

[](#4-use-in-your-controller)

```
public function index()
{
    $products = Product::all();
    return new ProductCollection($products);
}

public function show(Product $product)
{
    return new ProductResource($product);
}
```

### 5. Using the middleware:

[](#5-using-the-middleware)

The middleware is automatically registered by the package in the group specified in the configuration (default is 'api'). You can set the locale by adding a `lang` query parameter to your API requests, e.g., `?lang=pt` for Portuguese.

If you've disabled the automatic middleware registration, you can manually register it using one of these methods:

1. In your `app/Providers/AppServiceProvider.php`:

```
use Illuminate\Support\Facades\Route;
use BamboleeDigital\TranslatableResourceKit\Http\Middleware\SetLocale;

public function boot()
{
    Route::aliasMiddleware('set_locale', SetLocale::class);
    Route::pushMiddlewareToGroup('api', 'set_locale');
}
```

2. In your `routes/api.php`:

```
use BamboleeDigital\TranslatableResourceKit\Http\Middleware\SetLocale;

Route::middleware([SetLocale::class])->group(function () {
    // Your API routes here
});
```

3. For Laravel versions with `app/Http/Kernel.php`:

```
protected $middlewareGroups = [
    'api' => [
        // ...
        \BamboleeDigital\TranslatableResourceKit\Middleware\SetLocale::class,
    ],
];
```

Example
-------

[](#example)

Here's an example of how the JSON response changes when using this package:

Before:

```
{
  "id": 1,
  "name": {
    "en": "Laptop",
    "es": "Portátil",
    "pt": "Notebook"
  },
  "description": {
    "en": "Powerful laptop for professionals",
    "es": "Portátil potente para profesionales",
    "pt": "Notebook potente para profissionais"
  },
  "price": 999.99
}
```

After (assuming the current locale is 'pt', set via `?lang=pt`):

```
{
  "id": 1,
  "name": "Notebook",
  "description": "Notebook potente para profissionais",
  "price": 999.99
}
```

As you can see, the translated fields are automatically resolved to the current locale, simplifying the structure and making it easier to work with in frontend applications.

Advanced Usage
--------------

[](#advanced-usage)

### Customizing Recursion Depth

[](#customizing-recursion-depth)

You can customize the maximum recursion depth for nested translations in the `config/translatable-resource-kit.php` file:

```
return [
    'max_recursion_depth' => 3, // Default is 5
];
```

### Handling Nested Relations

[](#handling-nested-relations)

The `TranslatesAttributes` trait automatically handles nested relations. Make sure your relations are properly defined in your model's `$with` property:

```
class Product extends Model
{
    use HasTranslations, TranslatesAttributes;

    protected $with = ['category', 'tags'];

    // ...
}
```

### Customizing the Query Parameter

[](#customizing-the-query-parameter)

If you want to use a different query parameter instead of `lang`, you can modify the `SetLocale` middleware. You'll need to publish the middleware to your application:

```
php artisan vendor:publish --provider="BamboleeDigital\TranslatableResourceKit\TranslatableResourceKitServiceProvider" --tag="middleware"
```

Then, edit the published middleware file in `app/Http/Middleware/SetLocale.php` to change the query parameter name.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Bambolee Digital](https://github.com/bambolee-digital)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

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 ~1 days

Total

7

Last Release

603d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ea0811b77232bb232cc41a918466de4b146044ce293582045f2df13eeeeffd7f?d=identicon)[bambolee-digital](/maintainers/bambolee-digital)

---

Top Contributors

[![kellvembarbosa](https://avatars.githubusercontent.com/u/3621135?v=4)](https://github.com/kellvembarbosa "kellvembarbosa (12 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bambolee-digital-translatable-resource-kit/health.svg)

```
[![Health](https://phpackages.com/badges/bambolee-digital-translatable-resource-kit/health.svg)](https://phpackages.com/packages/bambolee-digital-translatable-resource-kit)
```

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