wiebenieuwenhuis/laravel-translatable-json

There is no license information available for the latest version (1.0) of this package.

Translate JSON objects

1.0 2022-08-27 14:42 UTC

This package is auto-updated.

Last update: 2024-11-08 12:12:51 UTC


README

This package extends the spatie translatable package and makes nested JSON data translatable.

Please note, when setting translatable json keys, all of them will be translatable (root keys and all nested keys).

Usage

namespace App\Models;

...
use Wiebenieuwenhuis\LaravelTranslatableJson\HasJsonTranslations;


class Post extends Model
{
    use HasJsonTranslations;
    
    public $translatableJson = [
        'content' => [
            'title',
            'content',
        ],
    ];
    
    ...

Whats happening

Input:

[
    [
        "title": "English title",
    ]
]

Will be saved as:

[
    [
        "title": [
            "en": "English title",
        ],
    ]
]

When setting a different locale (nl):

[
    [
        "title": "Nederlandse titel",
    ]
]

it will be saved as:

[
    [
        "title": [
            "en": "English title",
            "nl": "Nederlandse titel",
        ],
    ]
]