Giter Club home page Giter Club logo

locale-anywhere's Introduction

Laravel Nova Locale Anywhere Tool

This tool provides a nice header dropdown to quickly switch between locales (this locales are independent of the app()->getLocale() value and are stored in cache).

It also provides a Language field which gives you the status of the translation on a specific resource.

Installation

composer require sloveniangooner/locale-anywhere

Usage

To begin using this, you must first register the tool in NovaServiceProvider under tools. The tool utilises Spatie's Laravel Translatable package.

public function tools()
{
    return [
        new LocaleAnywhere([
            "locales" => [
                "en" => "English",
                "de" => "German"
            ],
            "useFallback" => false,
        ])
    ];
}

Define the field

You can then define the field in the resource.

use Sloveniangooner\LocaleAnywhere\Language;

Language::make("Language)

Extend trait

You also have to overwrite Spatie's HasTranslations trait in your model to allow toggling fallback locale and apply custom locale instead of app()->getLocale(). Don't worry - the package's trait extends all the functionalities Spatie's trait offers.

use Sloveniangooner\LocaleAnywhere\HasTranslations;
use Illuminate\Database\Eloquent\Model;

class Content extends Model {
    use HasTranslations;

    public $useFallback = true; // Local setting to use the fallback locale or not
}

For other options related to translations - please see Spatie's package. (spatie/laravel-translatable)[https://github.com/spatie/laravel-translatable]

Dropdown

The package provides a switch for the languages that you have to insert into Nova's layout file. You can do that by overwriting the layout.blade.php file and insert it after the user dropdown.

<dropdown class="ml-auto h-9 flex items-center dropdown-right">
    @include('nova::partials.user')
</dropdown>

<locale-anywhere-dropdown class="ml-6"></locale-anywhere-dropdown>

Delete translation toolbar button

The package provides a CustomDetailToolbar component that you can toggle via configuration. Optionally, you can also only grab the <delete-toolbar-button> from the package and paste it into your own custom detail toolbar.

new LocaleAnywhere(
    [
        "locales" => [
            "en" => "English",
            "de" => "German"
        ],
        "useFallback" => false,
        "customDetailToolbar" => false
    ]
)

locale-anywhere's People

Contributors

chancezeus avatar killgt avatar sloveniangooner avatar

Watchers

 avatar

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.