wiebenieuwenhuis / laravel-translatable-json
Translate JSON objects
Installs: 2 313
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- spatie/laravel-translatable: ^6.0.0
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", ], ] ]