Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move docs to larazeus site #15

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
317 changes: 40 additions & 277 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,302 +1,65 @@
# 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;

public function panel(Panel $panel): Panel
{
return $panel
// ...
->plugin(
SpatieLaravelTranslatablePlugin::make()
->defaultLocales(['en', 'es']),
);
}
```

## Preparing your model class
<h4 align="center">Lara Zeus Translatable is Filament support for Spatie's Laravel Translatable package.</h4>

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).
## Support Filament

## Preparing your resource class
<a href="https://github.com/sponsors/danharrin">
<img alt="filament-logo" src="https://larazeus.com/images/filament-sponsor-banner.png">
</a>

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:

```php
use Filament\Actions;
use Filament\Resources\Pages\ManageRecords;

class ManageBlogPosts extends ListRecords
{
use ManageRecords\Concerns\Translatable;

protected function getHeaderActions(): array
{
return [
Actions\LocaleSwitcher::make(),
// ...
];
}

// ...
}
```

### Setting the translatable locales for a particular resource

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:
## Introduction

```php
use Filament\Resources\Concerns\Translatable;
use Filament\Resources\Resource;
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 BlogPostResource extends Resource
{
use Translatable;

// ...

public static function getTranslatableLocales(): array
{
return ['en', 'fr'];
}
}
```
Our objective is to address existing issues, introduce additional features, and enhance the overall functionality of the plugin.

## Translating relation managers
We are committed to providing ongoing improvements and welcome contributions and suggestions from the community.

First, you must apply the `Filament\Resources\RelationManagers\Concerns\Translatable` trait to the relation manager class:
## Features

```php
use Filament\Resources\RelationManagers\Concerns\Translatable;
use Filament\Resources\RelationManagers\RelationManager;
- 🔥 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 BlogPostsRelationManager extends RelationManager
{
use Translatable;

// ...
}
```
## Translatable Pro

Now, you can add a new `LocaleSwitcher` action to the header of the relation manager's `table()`:
[![translatable-pro](https://larazeus.com/images/translatable-pro-ad.png)](https://larazeus.com/translatable-pro)

```php
use Filament\Tables;
use Filament\Tables\Table;
## Full Documentation

public function table(Table $table): Table
{
return $table
->columns([
// ...
])
->headerActions([
// ...
Tables\Actions\LocaleSwitcher::make(),
]);
}
```
> Visit our website to get the complete documentation: https://larazeus.com/docs/translatable

### Inheriting the relation manager's active locale from the resource page

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
- [php coder](https://github.com/atmonshi)
- [Dan Harrin](https://github.com/danharrin)
- [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.
Loading