PHPackages                             doriiaan/filament-astrotomic - 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. doriiaan/filament-astrotomic

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

doriiaan/filament-astrotomic
============================

Filament plugin which allows translations to be added to Filament resources.

v1.1.0(2mo ago)64.2k↓30.6%4[1 issues](https://github.com/Doriiaan/filament-astrotomic/issues)[1 PRs](https://github.com/Doriiaan/filament-astrotomic/pulls)1MITPHPPHP ^8.2CI passing

Since Aug 9Pushed 2mo agoCompare

[ Source](https://github.com/Doriiaan/filament-astrotomic)[ Packagist](https://packagist.org/packages/doriiaan/filament-astrotomic)[ Docs](https://github.com/Doriiaan/filament-astrotomic/)[ RSS](/packages/doriiaan-filament-astrotomic/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (24)Versions (3)Used By (1)

Filament Astrotomic
===================

[](#filament-astrotomic)

[![Latest Version](https://camo.githubusercontent.com/d7ffcc20625ad458ad146188d14f87d91ba78deee90f1d849460f27118888ff4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f446f72696961616e2f66696c616d656e742d617374726f746f6d6963)](https://packagist.org/packages/Doriiaan/filament-astrotomic)[![Total Downloads](https://camo.githubusercontent.com/032e35b7a9b1fbcb14b7b378d44278c71d12d5f84da95dc37de852afaa31905f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f446f72696961616e2f66696c616d656e742d617374726f746f6d6963)](https://packagist.org/packages/Doriiaan/filament-astrotomic)

This package is an extension for [Filament](https://filamentphp.com) and [laravel-translatable](https://docs.astrotomic.info/laravel-translatable).

> This package is a copy of [cactus-galaxy/filament-astrotomic](https://github.com/CactusGalaxy/FilamentAstrotomic) for Filament 4. The original package is no longer maintained.

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

[](#installation)

You can install the package via Composer:

```
composer require doriiaan/filament-astrotomic
```

Publish configs for [`astrotomic/laravel-translatable`](https://docs.astrotomic.info/laravel-translatable/installation#configuration) package:

```
php artisan vendor:publish --tag="translatable"
```

After this, you will have to configure the locales your app should use.

```
'locales' => [
    'uk',
    'en',
],
```

Adding the plugin to a panel
----------------------------

[](#adding-the-plugin-to-a-panel)

To add a plugin to a panel, you must include it in the configuration file using the `plugins()` method:

```
use Doriiaan\FilamentAstrotomic\FilamentAstrotomicPlugin;

public function panel(Panel $panel): Panel
{
    return $panel
        // ...
        ->plugins([
            FilamentAstrotomicPlugin::make(),
        ]);
}
```

Preparing your model class
--------------------------

[](#preparing-your-model-class)

You need to make your model translatable. You can read how to do this in [documentation for Laravel translatable](https://docs.astrotomic.info/laravel-translatable/installation#models).

Preparing your resource class
-----------------------------

[](#preparing-your-resource-class)

You must apply the `ResourceTranslatable` trait to your resource class:

```
use Doriiaan\FilamentAstrotomic\Resources\Concerns\ResourceTranslatable;
use Filament\Resources\Resource;

class CourseResource extends Resource
{
    use ResourceTranslatable;

    // ...
}
```

Making resource pages 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 `{Type}Translatable` trait to it:

```
use Doriiaan\FilamentAstrotomic\Resources\Pages\ListTranslatable;
use Filament\Resources\Pages\ListRecords;

class ListProducts extends ListRecords
{
    use ListTranslatable;

    // ...
}
```

```
use Doriiaan\FilamentAstrotomic\Resources\Pages\CreateTranslatable;
use Filament\Resources\Pages\CreateRecord;

class CreateProduct extends CreateRecord
{
    use CreateTranslatable;

    // ...
}
```

```
use Doriiaan\FilamentAstrotomic\Resources\Pages\EditTranslatable;
use Filament\Resources\Pages\EditRecord;

class EditProduct extends EditRecord
{
    use EditTranslatable;

    // ...
}
```

And if you have a `ViewRecord` page for your resource:

```
use Doriiaan\FilamentAstrotomic\Resources\Pages\ViewTranslatable;
use Filament\Resources\Pages\ViewRecord;

class ViewProduct extends ViewRecord
{
    use ViewTranslatable;

    // ...
}
```

### Setting the translatable locales for a particular resource

[](#setting-the-translatable-locales-for-a-particular-resource)

By default, the translatable locales loaded using [Astrotomic's Locales helper from method `all()`](https://docs.astrotomic.info/laravel-translatable/package/locales-helper#all)which returns all locales from the `translatable.locales` configuration. Alternatively, you can customize the translatable locales for a particular resource by overriding the `getTranslatableLocales()` method in your resource class:

```
use CactusGalaxy\FilamentAstrotomic\Resources\Concerns\ResourceTranslatable;
use Filament\Resources\Resource;

class CourseResource extends Resource
{
    use ResourceTranslatable;

    // ...

    public static function getTranslatableLocales(): array
    {
        return ['uk', 'en'];
    }
}
```

Using locale tabs on the form
-----------------------------

[](#using-locale-tabs-on-the-form)

`TranslatableTabs` extends the default [`Filament\Schemas\Components\Tabs`](https://filamentphp.com/docs/4.x/schemas/tabs) component and provides a way to create tab schema tabs for each locale. Within the `localeTabSchema` method, you can define the callback for schema for each tab. This callback will be called for each locale to generate scheme for tab.

To accept the `TranslatableTab` instance as an argument to get the current locale you need to name argument as `$translatableTab` or use type hint, like in example bellow.

Here is an example of how to use `TranslatableTabs` in the `CourseResource` form:

```
