PHPackages                             bbs-lab/nova-translation - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. bbs-lab/nova-translation

ActiveLibrary[Localization &amp; i18n](/categories/localization)

bbs-lab/nova-translation
========================

v5.3.3(5mo ago)119.4k↓33.3%6[1 PRs](https://github.com/BBS-Lab/nova-translation/pulls)MITPHPPHP ^8.1

Since Dec 3Pushed 5mo ago5 watchersCompare

[ Source](https://github.com/BBS-Lab/nova-translation)[ Packagist](https://packagist.org/packages/bbs-lab/nova-translation)[ RSS](/packages/bbs-lab-nova-translation/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (17)Versions (60)Used By (0)

Laravel Nova Translation
========================

[](#laravel-nova-translation)

[![StyleCI](https://camo.githubusercontent.com/78cf828a2ab6e73bc61da2737725f0246772a87c89b59b341e07988661ec1fb1/68747470733a2f2f7374796c6563692e696f2f7265706f732f3232313636313937322f736869656c64)](https://styleci.io/repos/221661972)[![Quality Score](https://camo.githubusercontent.com/0dbbeda6fbbdcc2f3ae7ae9d46c3f4413643d3827d85a76c4f8f7a017bbda9aa/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6262732d6c61622f6e6f76612d7472616e736c6174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/bbs-lab/nova-translation)

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Locale resource](#locale-resource)
    - [TranslationMatrix tool](#translationmatrix-tool)
- [GraphQL](#graphql)

Installation
------------

[](#installation)

You can install the nova tool in to a Laravel app that uses [Nova](https://nova.laravel.com) 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
------------

[](#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
------------

[](#configration)

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

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

### Using Cookies

[](#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
-----------

[](#config-nova)

Add `SetLocale` middleware in application kernel.

```
// app/Http/Kernel.php

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

Usage
-----

[](#usage)

### TranslationMatrix tool

[](#translationmatrix-tool)

You must register the translation matrix backend tool with [Nova](https://nova.laravel.com):

```
// app/Providers/NovaServiceProvider.php

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

### Nova resource

[](#nova-resource)

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

### Locale resource

[](#locale-resource)

And you can add the Locale [Nova](https://nova.laravel.com) Resource within your application:

```
// app/Nova/Locale.php
