bbs-lab/nova-translation is a Laravel package.
It currently has 1 GitHub stars and 19.700 downloads on Packagist (latest version v5.4.1).
Install it with composer require bbs-lab/nova-translation.
Discover more Laravel packages by bbs-lab
or browse all Laravel packages to compare alternatives.
Last updated
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
// @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();
}
You can publish the default configuration by running the following command :
php artisan vendor:publish --provider="BBSLab\NovaTranslation\NovaTranslationServiceProvider"
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(),
]);
}
}
Add SetLocale middleware in application kernel.
// app/Http/Kernel.php
protected $middleware = [
// ...
\BBSLab\NovaTranslation\Http\Middleware\SetLocale::class,
];
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 MUST extends BBSLab\NovaTranslation\Resources\TranslatableResource to work.
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;
}
If your using Lighthouse PHP you can add some default Directive and endpoints for Locale and Label.
@allTranslations, @paginateTranslations, @firstTranslation relatedActing 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'],
],
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 UTF-8 (e.g en.json) came from EmojiTerra