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

Allow users to customize the translation resource #18

Merged
merged 2 commits into from
Aug 1, 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
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ $panel->plugin(\TomatoPHP\FilamentTranslations\FilamentTranslationsSwitcherPlugi

You can scan your project to get all the languages tags and save them to the database


```bash
php artisan filament-translations:import
```
Expand Down Expand Up @@ -228,6 +227,16 @@ You can show or hide the buttons in the UI by changing the config file. By defau
'show_scan_button' => false ,
```

### Custom Resource

You can create your own resource to show the translations in the UI, add your custom resource class to the config file like this:

```php
'translation_resource' => CustomResource::class,
```

This is especially useful when you want to have complete control over the UI but still want to use the translations package. Think about implementing a check on user roles when using `shouldRegisterNavigation` in your custom resource.

## Other Filament Packages

- [Filament Users Resource](https://www.github.com/tomatophp/filament-users)
Expand Down
9 changes: 9 additions & 0 deletions config/filament-translations.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@
'export_enabled' => true,
'import_enabled' => true,


/*
|--------------------------------------------------------------------------
|
| Translation resource.
|
*/
'translation_resource' => \TomatoPHP\FilamentTranslations\Resources\TranslationResource::class,

/*
|--------------------------------------------------------------------------
|
Expand Down
15 changes: 11 additions & 4 deletions src/FilamentTranslationsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\View\View;
use Kenepa\TranslationManager\Http\Middleware\SetLanguage;
use TomatoPHP\FilamentTranslations\Http\Middleware\LanguageMiddleware;
use TomatoPHP\FilamentTranslations\Resources\TranslationResource;


class FilamentTranslationsPlugin implements Plugin
Expand All @@ -24,9 +23,17 @@ public function getId(): string

public function register(Panel $panel): void
{
$panel->resources([
TranslationResource::class
]);
$panel
->resources([
config('filament-translations.translation_resource'),
]);

if (config('filament-translations.language_switcher')) {
$panel->renderHook(
config('filament-translations.language_switcher_render_hook'),
fn (): View => $this->getLanguageSwitcherView()
);

}

public function allowGPTScan(bool $allowGPTScan=true): self
Expand Down