PHP code example of kkhomeriki / nova-translatable

1. Go to this page and download the library: Download kkhomeriki/nova-translatable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kkhomeriki / nova-translatable example snippets


public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        Translatable::make([
            Text::make('title'),
            Trix::make('text'),
        ]),
    ];
}

// in any service provider

\Spatie\NovaTranslatable\Translatable::defaultLocales(['en', 'fr']);

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        Translatable::make([
            Text::make('title'),
            Trix::make('text'),
        ]),
    ];
}

Translatable::make([
    Text::make('title'),
    Trix::make('text'),
])->locales(['de', 'es']),

Translatable::displayLocalizedNameByDefaultUsing(function(Field $field, string $locale) {
   return ucfirst($field->name) . " [{$locale}]";
})

Translatable::make([
    Text::make('title'),
    Trix::make('text'),
])->displayLocalizedNameUsing(function(Field $field, string $locale) {
   return ucfirst($field->name) . " --- {$locale}]";
}),

Translatable::make([
    Text::make('My title', 'title'),
    Trix::make('text'),
])->displayLocalizedNameUsing(function(Field $field, string $locale) {
   return ucfirst($field->name) . " [{$locale}]";
}),