optimistdigital/nova-locale-manager

Laravel Nova tool to manage locales.

2.0.2 2020-05-26 15:03 UTC

This package is auto-updated.

Last update: 2020-07-26 15:18:43 UTC


README

This Laravel Nova package allows you to manage simple locales.

Features

  • Locale management (name and slug)

Installation

Install the package in a Laravel Nova project via Composer:

composer require optimistdigital/nova-locale-manager

Run the database migration(s):

php artisan migrate

Register the tool with Nova in the tools() method of the NovaServiceProvider:

// in app/Providers/NovaServiceProvider.php

public function tools()
{
    return [
        // ...
        new \OptimistDigital\NovaLocaleManager\NovaLocaleManager
    ];
}

Usage

nova_get_locales($activeOnly = false)

Parameter $activeOnly decides wether to return only active locales or all.

Returns the locales as a slug => name map.

[
    'en' => 'English',
    'et' => 'Estonian',
]

nova_get_locales_full($activeOnly = false)

Parameter $activeOnly decides wether to return only active locales or all.

Returns the locales and all their data.

[
    [
        'name' => 'English',
        'slug' => 'en',
        'active' => false,
        'default' => false,
    ],
    [
        'name' => 'Estonian',
        'slug' => 'et',
        'active' => true,
        'default' => true,
    ],
]

nova_get_default_locale()

Returns the default locale's full data.

[
    'name' => 'English',
    'slug' => 'en',
    'active' => false,
    'default' => false,
],

nova_get_default_locale_slug()

Returns the default locale's slug.

'en'

Handling locale deletion

You can get register a callback for when a locale is deleted using the NovaLocaleManager::deleteCallback() function. You can register the call back in NovaServiceProvider's boot() function.

Example:

// in app/Providers/NovaServiceProvider.php

public function boot()
{
    \OptimistDigital\NovaLocaleManager\NovaLocaleManager::deleteCallback(function ($locale) {
        // $locale is the Locale model
        // Locale ID: $locale->id
        // Locale slug: $locale->locale
        // Locale name: $locale->name
    });
}

Credits

License

Nova Locale Manager is open-sourced software licensed under the MIT license.