/nova-translatable

A Laravel Nova package that allows you to make any input field translatable.

Primary LanguageVueMIT LicenseMIT

Nova Translatable

Latest Version on Packagist Total Downloads

This Laravel Nova allows you to make any input field spatie/laravel-translatable compatible and localisable.

Requirements

  • laravel/nova: ^2.9
  • spatie/laravel-translatable: ^4.0

Features

  • Supports almost all fields (including third party ones)
  • Supports default validation automatically
  • Simple to implement with minimal code changes (after spatie/laravel-translatable support)
  • Locale tabs to switch between different locale values of the same field
  • Double click on a tab to switch all fields to that locale
  • Supports nova-settings package

Screenshots

Detail View

Form View

Form View w/ Validation Errors

Installation

Firstly, set up spatie/laravel-translatable.

Install the package in a Laravel Nova project via Composer:

# Install nova-translatable
composer require optimistdigital/nova-translatable

# Publish configuration (optional, but useful for setting default locales)
php artisan vendor:publish --tag="nova-translatable-config"

Usage

Call ->translatable() on any field, like so:

// Any Nova field
Text::make('Name')
  ->rules('required', 'min:2')
  ->translatable(),

// Any third-party input field
Multiselect::make('Football teams')
  ->rules('required')
  ->translatable(),

// Optionally pass custom locales on a per-field basis
Number::make('Population')
  ->translatable([
    'en' => 'English',
    'et' => 'Estonian',
  ]),

Configuration

You can define default locales for all the translatable fields in the config file. The config file can be published using:

php artisan vendor:publish --tag="nova-translatable-config"

Credits

License

This project is open-sourced software licensed under the MIT license.