whitecube / nova-translatable
A Laravel Nova field for dimsav/laravel-translatable.
Installs: 525
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 0
Open Issues: 0
Language:Vue
Requires
- php: >=7.1.0
- dimsav/laravel-translatable: ^9.0
This package is auto-updated.
Last update: 2019-02-26 15:18:40 UTC
README
This package is a fork of yeswedev/ywd_nova-translatable which itself is based on mrmonat/nova-translatable.
Adds the ability to show and edit translated fields created with dimsav/laravel-translatable package.
It will show up in the detail view like this:
And in the edit view like this:
Installation and usage
You can require this package using composer:
composer require whitecube/nova-translatable
You can add the field follows:
use Whitecube\Nova\Translatable\Translatable; Translatable::make('Description'),
Make sure, that you have your Eloquent model setup correct:
- First, you need to add the
Dimsav\Translatable\Translatable
-trait. - Next, you should create a public property
$translatedAttributes
which holds an array with all the names of attributes you wish to make translatable. - Finally, you should make sure that all translatable attributes are set to the
text
-datatype in your database. If your database supportsjson
-columns, use that.
Here's an example of a prepared model:
use Illuminate\Database\Eloquent\Model; use Dimsav\Translatable\Translatable; class NewsItem extends Model { use Translatable; public $translatedAttributes = ['name']; }
Defining Locales
Locales can be defined via config file config/translatable.php
by adding a locales
array:
// config/translatable.php return [ ... 'locales' => [ 'en', 'de', 'fr', ], ];
Alternatively you can "override" the config locales with the locales(...)
method:
Translatable::make('Description')->locales([ 'en' => 'English', 'de' => 'German', ]),
Single Line Option
By default the input field on the edit view is a textarea. If you want to change it to a single line input field you can add the singleLine()
option:
Translatable::make('Description')->locales([...])->singleLine(),
Markdown Editor
You can use the SimpleMDE Markdown editor for your translated fields by using the md()
option:
Translatable::make('Description')->md(),
Trix Editor
You can use the trix editor for your translated fields by using the trix()
option:
Translatable::make('Description')->trix(),
Index View
By default the locale used when displaying the field on the index view is determined by app()->getLocale()
. To override this you can use the indexLocale($locale)
option:
Translatable::make('Description')->indexLocale('de'),