GithubHelp home page GithubHelp logo

outl1ne / nova-lang Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 2.0 1.09 MB

This Laravel Nova package allows you to sort Nova resource's index view and assign locales to resources

License: MIT License

PHP 42.80% Vue 48.48% JavaScript 7.77% SCSS 0.11% Blade 0.84%
nova laravel-nova laravel-nova-tool locale

nova-lang's Introduction

Nova Lang

Laravel Nova package that allows you to set localization of content.

NovaLang

Installation

Install the package in a Laravel Nova project via Composer and run migrations:

# Install package
composer require optimistdigital/nova-lang

Publish the nova-lang configuration file and edit it to your preference:

php artisan vendor:publish --provider="OptimistDigital\NovaLang\ToolServiceProvider" --tag="config"

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

// in app/Providers/NovaServiceProvider.php

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

Defining locales

// in /config/nova-lang.php

// ...
'locales' => [
  'en' => 'English',
  'et' => 'Estonian',
],

// OR

'locales' => function () {
  return Locale::all()->pluck('name', 'key');
},

After defining locales in /config/nova-lang.php, you can use helper function.

$locales = nova_lang_get_all_locales();

//or you can use it in another package.

'locales' => nova_lang_get_all_locales(),

Usage

Creating the field

$fields[] = NovaLangField::make('Locale', 'locale');

If you are using a translation package like nova-locale-field, you can also give locale_parent_id. localeParentId has to be optainable through url query. Make sure you have defined locale_parent_id in your database.

$fields[] = NovaLangField::make('Locale', 'locale', 'locale_parent_id')

Sort resources by locale

//Your resource file, where you have returned $fields array
public static function indexQuery(NovaRequest $request, $query)
{
    $localeColumn = 'your_table_name' . 'locale'
    $query->where(function ($subQuery) use ($localeColumn) {
        $subQuery->where($localeColumn, nova_lang_get_active_locale())
            ->orWhereNotIn($localeColumn, array_keys(nova_lang_get_all_locales()));
    });
    return $query;
}

Credits

License

Nova page manager is open-sourced software licensed under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.