Looking to hire Laravel developers? Try LaraJobs
This package is not available.

laravel-translatable-json maintained by wiebenieuwenhuis

Description
Translate JSON objects
Last update
2022/08/27 16:42 (dev-master)
Links
Downloads
3 617

Comments
comments powered by Disqus

laravel-translatable-json

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",
        ],
    ]
]