forked from filamentphp/spatie-laravel-translatable-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,020 additions
and
678 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,302 +1,77 @@ | ||
# Filament Spatie Translatable Plugin | ||
<p align="center"> | ||
<a href="https://larazeus.com"><img src="https://larazeus.com/images/lara-zeus-translatable.png" /></a> | ||
</p> | ||
|
||
## Introduction | ||
|
||
This repository is a fork of the [Filament Spatie Laravel Translatable plugin](https://github.com/filamentphp/spatie-laravel-translatable-plugin), maintained by [Mohamed Sabil](https://github.com/mohamedsabil83) and [Lara Zeus](https://github.com/lara-zeus). | ||
|
||
Our objective is to address existing issues, introduce additional features, and enhance the overall functionality of the plugin. | ||
|
||
We are committed to providing ongoing improvements and welcome contributions and suggestions from the community. | ||
|
||
## Installation | ||
|
||
First add this repo URL to your composer: | ||
|
||
```json | ||
"repositories": [ | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/lara-zeus/translatable" | ||
}, | ||
] | ||
``` | ||
|
||
and make sure your minimum stability is set to dev: | ||
|
||
```json | ||
"minimum-stability": "dev", | ||
``` | ||
|
||
Then Install the plugin with Composer: | ||
|
||
```bash | ||
composer require filament/spatie-laravel-translatable-plugin:"^3.2" -W | ||
``` | ||
|
||
## Adding the plugin to a panel | ||
|
||
To add a plugin to a panel, you must include it in the configuration file using the `plugin()` method: | ||
|
||
```php | ||
use Filament\SpatieLaravelTranslatablePlugin; | ||
|
||
public function panel(Panel $panel): Panel | ||
{ | ||
return $panel | ||
// ... | ||
->plugin(SpatieLaravelTranslatablePlugin::make()); | ||
} | ||
``` | ||
|
||
## Setting the default translatable locales | ||
|
||
To set up the locales that can be used to translate content, you can pass an array of locales to the `defaultLocales()` plugin method: | ||
|
||
```php | ||
use Filament\SpatieLaravelTranslatablePlugin; | ||
<h4 align="center">Lara Zeus Translatable is Filament support for Spatie's Laravel Translatable package.</h4> | ||
|
||
public function panel(Panel $panel): Panel | ||
{ | ||
return $panel | ||
// ... | ||
->plugin( | ||
SpatieLaravelTranslatablePlugin::make() | ||
->defaultLocales(['en', 'es']), | ||
); | ||
} | ||
``` | ||
## Support Filament | ||
|
||
## Preparing your model class | ||
<a href="https://github.com/sponsors/danharrin"> | ||
<img alt="filament-logo" src="https://larazeus.com/images/filament-sponsor-banner.png"> | ||
</a> | ||
|
||
You need to make your model translatable. You can read how to do this in [Spatie's documentation](https://spatie.be/docs/laravel-translatable/installation-setup#content-making-a-model-translatable). | ||
|
||
## Preparing your resource class | ||
|
||
You must apply the `Filament\Resources\Concerns\Translatable` trait to your resource class: | ||
|
||
```php | ||
use Filament\Resources\Concerns\Translatable; | ||
use Filament\Resources\Resource; | ||
|
||
class BlogPostResource extends Resource | ||
{ | ||
use Translatable; | ||
|
||
// ... | ||
} | ||
``` | ||
|
||
## Making resource pages translatable | ||
|
||
After [preparing your resource class](#preparing-your-resource-class), you must make each of your resource's pages translatable too. You can find your resource's pages in the `Pages` directory of each resource folder. To prepare a page, you must apply the corresponding `Translatable` trait to it, and install a `LocaleSwitcher` header action: | ||
|
||
```php | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ListRecords; | ||
|
||
class ListBlogPosts extends ListRecords | ||
{ | ||
use ListRecords\Concerns\Translatable; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\LocaleSwitcher::make(), | ||
// ... | ||
]; | ||
} | ||
|
||
// ... | ||
} | ||
``` | ||
|
||
```php | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\CreateRecord; | ||
|
||
class CreateBlogPost extends CreateRecord | ||
{ | ||
use CreateRecord\Concerns\Translatable; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\LocaleSwitcher::make(), | ||
// ... | ||
]; | ||
} | ||
|
||
// ... | ||
} | ||
``` | ||
|
||
```php | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditBlogPost extends EditRecord | ||
{ | ||
use EditRecord\Concerns\Translatable; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\LocaleSwitcher::make(), | ||
// ... | ||
]; | ||
} | ||
|
||
// ... | ||
} | ||
``` | ||
|
||
And if you have a `ViewRecord` page for your resource: | ||
|
||
```php | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ViewRecord; | ||
|
||
class ViewBlogPost extends ViewRecord | ||
{ | ||
use ViewRecord\Concerns\Translatable; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\LocaleSwitcher::make(), | ||
// ... | ||
]; | ||
} | ||
|
||
// ... | ||
} | ||
``` | ||
|
||
If you're using a simple resource, you can make the `ManageRecords` page translatable instead: | ||
## Introduction | ||
|
||
```php | ||
use Filament\Actions; | ||
use Filament\Resources\Pages\ManageRecords; | ||
This repository is a fork of the [Filament Spatie Laravel Translatable plugin](https://github.com/filamentphp/spatie-laravel-translatable-plugin), maintained by [Mohamed Sabil](https://github.com/mohamedsabil83) and [Lara Zeus](https://github.com/lara-zeus). | ||
|
||
class ManageBlogPosts extends ListRecords | ||
{ | ||
use ManageRecords\Concerns\Translatable; | ||
|
||
protected function getHeaderActions(): array | ||
{ | ||
return [ | ||
Actions\LocaleSwitcher::make(), | ||
// ... | ||
]; | ||
} | ||
|
||
// ... | ||
} | ||
``` | ||
Our objective is to address existing issues, introduce additional features, and enhance the overall functionality of the plugin. | ||
|
||
### Setting the translatable locales for a particular resource | ||
We are committed to providing ongoing improvements and welcome contributions and suggestions from the community. | ||
|
||
By default, the translatable locales can be [set globally for all resources in the plugin configuration](#setting-the-default-translatable-locales). Alternatively, you can customize the translatable locales for a particular resource by overriding the `getTranslatableLocales()` method in your resource class: | ||
## Features | ||
|
||
```php | ||
use Filament\Resources\Concerns\Translatable; | ||
use Filament\Resources\Resource; | ||
- 🔥 Using Spatie translatable package | ||
- 🔥 default translatable locales | ||
- 🔥 Locale Switcher | ||
- 🔥 Support for create, edit, list and view pages | ||
- 🔥 Setting the translatable locales for a particular resource | ||
- 🔥 Translating relation managers | ||
|
||
class BlogPostResource extends Resource | ||
{ | ||
use Translatable; | ||
|
||
// ... | ||
|
||
public static function getTranslatableLocales(): array | ||
{ | ||
return ['en', 'fr']; | ||
} | ||
} | ||
``` | ||
## Full Documentation | ||
|
||
## Translating relation managers | ||
> Visit our website to get the complete documentation: https://larazeus.com/docs/translatable | ||
First, you must apply the `Filament\Resources\RelationManagers\Concerns\Translatable` trait to the relation manager class: | ||
### Important Note on Using the Local Switcher | ||
|
||
```php | ||
use Filament\Resources\RelationManagers\Concerns\Translatable; | ||
use Filament\Resources\RelationManagers\RelationManager; | ||
Please be aware that there are some known limitations when using the local switcher with certain complex field types. | ||
|
||
class BlogPostsRelationManager extends RelationManager | ||
{ | ||
use Translatable; | ||
|
||
// ... | ||
} | ||
``` | ||
To avoid potential issues, we recommend disabling the local switcher and using the specified field types instead. | ||
|
||
Now, you can add a new `LocaleSwitcher` action to the header of the relation manager's `table()`: | ||
#### Available Components for Translatable Fields: | ||
|
||
```php | ||
use Filament\Tables; | ||
use Filament\Tables\Table; | ||
* https://filamentphp.com/plugins/solution-forest-translate-field | ||
* https://filamentphp.com/plugins/mvenghaus-translatable-inline | ||
* https://filamentphp.com/plugins/outerweb-translatable-fields | ||
* https://filamentphp.com/plugins/34ml-translatable-field | ||
|
||
public function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
// ... | ||
]) | ||
->headerActions([ | ||
// ... | ||
Tables\Actions\LocaleSwitcher::make(), | ||
]); | ||
} | ||
``` | ||
You can also create your own custom fields. Please refer to the following example: | ||
|
||
### Inheriting the relation manager's active locale from the resource page | ||
* https://github.com/lara-zeus/chaos/blob/1.x/src/Forms/Components/MultiLang.php | ||
|
||
If you wish to reactively inherit the locale of the `Translatable` resource page that the relation manager is being displayed on, you can override the `$activeLocale` property and add Livewire's `Reactive` attribute to it: | ||
## Changelog | ||
|
||
```php | ||
use Filament\Resources\RelationManagers\Concerns\Translatable; | ||
use Filament\Resources\RelationManagers\RelationManager; | ||
use Livewire\Attributes\Reactive; | ||
Please see [CHANGELOG](CHANGELOG.md) for more information on recent changes. | ||
|
||
class BlogPostsRelationManager extends RelationManager | ||
{ | ||
use Translatable; | ||
|
||
#[Reactive] | ||
public ?string $activeLocale = null; | ||
|
||
// ... | ||
} | ||
``` | ||
## Support | ||
available support channels: | ||
* open an issue on [GitHub](https://github.com/lara-zeus/translatable/issues) | ||
* Email us using the [contact center](https://larazeus.com/contact-us) | ||
|
||
If you do this, you no longer need a `LocaleSwitcher` action in the `table()`. | ||
## Contributing | ||
|
||
### Setting the translatable locales for a particular relation manager | ||
Please see [CONTRIBUTING](CONTRIBUTING.md) for details. | ||
|
||
By default, the translatable locales can be [set globally for all relation managers in the plugin configuration](#setting-the-default-translatable-locales). Alternatively, you can customize the translatable locales for a particular relation manager by overriding the `getTranslatableLocales()` method in your relation manager class: | ||
## Security | ||
|
||
```php | ||
use Filament\Resources\RelationManagers\Concerns\Translatable; | ||
use Filament\Resources\RelationManagers\RelationManager; | ||
If you find any security-related issues, please email [email protected] instead of using the issue tracker. | ||
|
||
class BlogPostsRelationManager extends RelationManager | ||
{ | ||
use Translatable; | ||
|
||
// ... | ||
|
||
public function getTranslatableLocales(): array | ||
{ | ||
return ['en', 'fr']; | ||
} | ||
} | ||
``` | ||
## Credits | ||
|
||
## Publishing translations | ||
- [Dan Harrin](https://github.com/danharrin) | ||
- [php coder](https://github.com/atmonshi) | ||
- [Mohamed Sabil](https://github.com/mohamedsabil83) | ||
- [All Contributors](../../contributors) | ||
|
||
If you wish to translate the package, you may publish the language files using: | ||
## License | ||
|
||
```bash | ||
php artisan vendor:publish --tag=filament-spatie-laravel-translatable-plugin-translations | ||
``` | ||
The MIT License (MIT). Please have a look at [License File](LICENSE.md) for more information. |
Oops, something went wrong.