PHP code example of digitalcloud / multilingual-nova

1. Go to this page and download the library: Download digitalcloud/multilingual-nova 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/ */

    

digitalcloud / multilingual-nova example snippets




return [

    /*
     * The source of supported locales on the application.
     * Available selection "array", "database". Default array.
     * When you set source "array" you can declare your languages from below at locales.
     * And when you set source "database" you can declare languages model from below and follow database instructions.
    */
    'source' => 'array',

    /*
     * If you choose array selection, you should add all supported translation on it as "code" => "label"
     */
    'locales' => [
        'en' => 'English',
        'ar' => 'Arabic',
        'de' => 'Deutsch'
    ],

    /*
     * If you choose database selection, you should create or choose the model responsible for retrieving supported translations.
     * If there is not existed model for retrieving supported translations, you must create a new model and must contain two columns from values "code_field", "label_field".
     * And choose the 'code_field' for example "en","ar","ru"...
     * And choose the 'label_field' which will be shown for users, for example "English","EN", ....
     */
    'database' => [
        'model' => 'App\\Language',
        'code_field' => 'code',
        'label_field' => 'label'
    ],

    /*
     * The view style you want to show on index & details page.
     * Available selection "button", "list", "mix" default button.
     */
    'style' => 'button',

    /*
     * If you choose mix selection, you can define after how many languages should the button convert to list.
     */
    'convert_to_list_after' => 3
];


use Digitalcloud\MultilingualNova\NovaLanguageTool;
// ....

public function tools()
{
    return [
        // ...
        new NovaLanguageTool(),
        // ...
    ];
}


    use Digitalcloud\MultilingualNova\Multilingual;
    
    // ....
    
    public function fields(Request $request)
    {
        return [
            // ...
            Multilingual::make('Language'),
            // ...
        ];
    }

    use Spatie\Translatable\HasTranslations;
    
    // ....
    
    class User extends Model
    {
    
    use HasTranslations;
    
    protected $fillable = ['name'];

    protected $translatable = ['name'];
 
    }


    use Digitalcloud\MultilingualNova\Multilingual;
    
    // ....
    
    public function fields(Request $request)
    {
        return [
            // ...
            Multilingual::make('Language')->setLocales([
                  'ar' => 'Arabic',
                  'en' => 'English',
                  'de' => 'Deutsch',
            ]),
            // ...
        ];
    }
shell
php artisan vendor:publish --provider="Digitalcloud\MultilingualNova\FieldServiceProvider"