Giter Site home page Giter Site logo

nova-translation's Introduction

Laravel Nova Translation

StyleCI Quality Score

Contents

Installation

You can install the nova tool in to a Laravel app that uses Nova via composer:

composer require bbs-lab/nova-translation

The service provider will automatically get registered. Or you may manually add the service provider in your config/app.php file:

'providers' => [
    // ...
    BBSLab\NovaTranslation\NovaTranslationServiceProvider::class,
],

You can tailor default in your application by running:

php artisan vendor:publish --provider="BBSLab\NovaTranslation\NovaTranslationServiceProvider"

You need to run migrations and seeds Locales.

php artisan migrate

Models setup

// @TODO... Explain

  • use Traits\Translatable

  • auto_synced_models in config.php

  • Define $nonTranslatable attributes (attributes that will be overridden during in all translations during an entry update).

  • Define $onCreateTranslatable attributes (attributes that will be copied during translations entry creation).

  • If your using michielkempen/nova-order-field package you must override system in model with:

/**
 * {@inheritdoc}
 */
public function buildSortQuery()
{
    return static::query()->locale();
}

Configration

You can publish the default configuration by running the following command :

php artisan vendor:publish --provider="BBSLab\NovaTranslation\NovaTranslationServiceProvider"

Using Cookies

By default, the locale is stored in the session upon change, but if you need to access it before the session is started, you can instruct the package to save it in the cookies by enabling it in the config :

'use_cookies' => true,

The cookie will hold the same name defined in locale_session_key

๐Ÿ’ก NOTE: The cookie will be encrypted by default, to have it excluded you can add it to your EncryptCookies middleware :

class EncryptCookies extends Middleware
{
    public function __construct(EncrypterContract $encrypter)
    {
        parent::__construct($encrypter);

        $this->except = array_merge($this->except, [
            // ...
            NovaTranslation::localeSessionKey(),
        ]);
    }
}

Config Nova

Add SetLocale middleware in application kernel.

// app/Http/Kernel.php

protected $middleware = [
    // ...
    \BBSLab\NovaTranslation\Http\Middleware\SetLocale::class,
];

Usage

TranslationMatrix tool

You must register the translation matrix backend tool with Nova:

// app/Providers/NovaServiceProvider.php

public function tools()
{
    return [
        new \BBSLab\NovaTranslation\Tools\TranslationMatrix,
    ];
}

Nova resource

Nova Resource MUST extends BBSLab\NovaTranslation\Resources\TranslatableResource to work.

Locale resource

And you can add the Locale Nova Resource within your application:

// app/Nova/Locale.php

<?php

namespace App\Nova;

use App\Helpers\StaticLabel;
use BBSLab\NovaTranslation\Resources\Locale as BaseResource;

class Locale extends BaseResource
{
    /**
     * {@inheritdoc}
     */
    public static $group = StaticLabel::GROUP_ADMINISTRATION;
}

GraphQL

If your using Lighthouse PHP you can add some default Directive and endpoints for Locale and Label.

Directives @allTranslations, @paginateTranslations, @firstTranslation related

Acting as similar @all, @paginate, @first.

You need to add package Directives path to your lighthouse.php configuration file:

// config/lighthouse.php

'namespaces' => [
    // ...
    'directives' => ['App\\GraphQL\\Directives', 'BBSLab\\NovaTranslation\\GraphQL\\Directives'],
],

Schema

You can include those in your existing schema:

#import ../../../vendor/bbs-lab/nova-translation/src/Http/GraphQL/Locale/*.graphql
#import ../../../vendor/bbs-lab/nova-translation/src/Http/GraphQL/Label/*.graphql

Flags resources

Flags UTF-8 (e.g en.json) came from EmojiTerra

TODO

  • Add order button on keys heading
  • Add search bar to filter keys
  • Add checkboxes to enable/disable display of locale
  • Add custom message/component when no locale is selected

nova-translation's People

Contributors

bbs-smuller avatar crezra avatar mfrancois avatar mfrancoisbbs avatar mikaelpopowicz 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.