bbs-lab / nova-translation
Installs: 16 951
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 6
Forks: 5
Open Issues: 1
Requires
- php: ^7.2|^8.0
- ext-json: *
- illuminate/contracts: ^6.2|^7.0|^8.0|^9.0|^10.18|^11.0
- illuminate/database: ^6.2|^7.0|^8.0|^9.0|^10.18|^11.0
- illuminate/support: ^6.2|^7.0|^8.0|^9.0|^10.18|^11.0
- laravel/framework: ^6.2|^7.0|^8.0|^9.0|^10.18|^11.0
- laravel/nova: ^4.0
- nova-kit/nova-packages-tool: ^1.3.1
Requires (Dev)
- nuwave/lighthouse: ^4|^5.0
- dev-master
- 5.x-dev
- v5.1.0
- v5.0.0
- 4.x-dev
- v4.3.0
- v4.2.0
- v4.1.1
- v4.1.0
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- 3.x-dev
- v3.0.0
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.5
- v0.3.4
- v0.3.2
- v0.3.1
- v0.3.0
- 0.2.0
- 0.1.0
- v0.0.1
- dev-release/0.5.x
- dev-feature/laravel-11-support
- dev-dependabot/npm_and_yarn/webpack-5.76.1
- dev-nova-4
- dev-release/1.4.x
- dev-legacy/translatable
This package is auto-updated.
Last update: 2024-11-12 09:43:36 UTC
README
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