Getting started
Installation
Thank you for purchasing the AutoTranslator plugin for Filament!
We tried to make the plugin as easy-to-install and versatile as possible. Nevertheless, if you still have a question, feature request or found an unsupported translation, please send an e-mail to [email protected].
In this guide I'll show you how to install the plugin, so you can start using it right away.
Prerequisites
For these installation instructions to work, you'll need to have the Filament Panels package installed and configured.
The package is supported on Filament V3, V4 and V5; and Laravel 10 or higher.
Installation steps
Add Composer repository
Run the following command to add the private Composer repository:
composer config 'repositories.ralphjsmit/*' composer https://satis.ralphjsmit.com
The end result should look something like this:
"repositories": [
{
"type": "composer",
"url": "https://satis.ralphjsmit.com"
}
]
Require the package
Next, run the following command to require the package:
composer require ralphjsmit/laravel-filament-auto-translator
If you receive a question to allow the plugin to run code, select yes. Next, you will be prompted for your username (which is your e-mail) and your password (which is your license key, e.g. 8c21df8f-6273-4932-b4ba-8bcc723ef500).
If you are installing the package in a Filament V3 installation, you should require the version ^1.0 instead:
composer require ralphjsmit/laravel-filament-auto-translator:^1.0
Composer will ask if you want to store your credentials in your global auth.json.
If you want to store the credentials per project and not globally, run the following command to create an auth.json file in the root of your project instead:
composer config http-basic.satis.ralphjsmit.com {your_username} {your_password}
(Make sure not to commit the auth.json file by adding it to your .gitignore file.)
If you have a Solo-license and are getting a 403 error, then you probably have run out of device activations. Each new server/laptop/device counts as one activation. Check your license email for the link to remove existing activations or upgrade your license.
Enable auto-translations
The plugin works by generating the translations for all $livewire components that implement RalphJSmit\Filament\AutoTranslator\Contracts\HasTranslations.
Existing project
If you already have an existing project, you will need to choose whether you want to immediately enable the AutoTranslator for all resources, and potentially need to convert some translation keys, or if you only want to enable it for new resources.
For all resources/pages/clusters/widgets that you want to enable the auto translations for, extend the following files provided by the AutoTranslator instead of those provided by Filament. You can easily do this as a global search-and-replace:
| Replace | With |
|---|---|
Filament\Clusters\Cluster
|
RalphJSmit\Filament\AutoTranslator\Filament\Clusters\Cluster
|
Filament\Pages\Page
|
RalphJSmit\Filament\AutoTranslator\Filament\Pages\Page
|
Filament\Resources\Resource
|
RalphJSmit\Filament\AutoTranslator\Filament\Resources\Resource
|
Filament\Resources\RelationManagers\RelationManager
|
RalphJSmit\Filament\AutoTranslator\Filament\Resources\Resource\RelationManagers\RelationManager
|
Filament\Resources\Pages\CreateRecord
|
RalphJSmit\Filament\AutoTranslator\Filament\Resources\Resource\Pages\CreateRecord
|
Filament\Resources\Pages\EditRecord
|
RalphJSmit\Filament\AutoTranslator\Filament\Resources\Resource\Pages\EditRecord
|
Filament\Resources\Pages\ListRecords
|
RalphJSmit\Filament\AutoTranslator\Filament\Resources\Resource\Pages\ListRecords
|
Filament\Resources\Pages\ManageRecords
|
RalphJSmit\Filament\AutoTranslator\Filament\Resources\Resource\Pages\ManageRecords
|
Filament\Resources\Pages\ManageRelatedRecords
|
RalphJSmit\Filament\AutoTranslator\Filament\Resources\Resource\Pages\ManageRelatedRecords
|
Filament\Resources\Pages\Page
|
RalphJSmit\Filament\AutoTranslator\Filament\Resources\Resource\Pages\Page
|
Filament\Resources\Pages\ViewRecord
|
RalphJSmit\Filament\AutoTranslator\Filament\Resources\Resource\Pages\ViewRecord
|
Filament\Widgets\ChartWidget
|
RalphJSmit\Filament\AutoTranslator\Filament\Widgets\ChartWidget
|
Filament\Widgets\StatsOverviewWidget
|
RalphJSmit\Filament\AutoTranslator\Filament\Widgets\StatsOverviewWidget
|
Filament\Widgets\TableWidget
|
RalphJSmit\Filament\AutoTranslator\Filament\Widgets\TableWidget
|
Filament\Widgets\Widget
|
RalphJSmit\Filament\AutoTranslator\Filament\Widgets\Widget
|
Filament\Actions\Exports\Exporter
|
RalphJSmit\Filament\AutoTranslator\Filament\Actions\Exports\Exporter
|
Filament\Actions\Imports\Importer
|
RalphJSmit\Filament\AutoTranslator\Filament\Actions\Imports\Importer
|
Alternatively, if for the above classes you already have your own (abstract) base class in your application, then you can also implement the HasTranslations interface and add the following traits:
| Class | Trait |
|---|---|
| Cluster |
RalphJSmit\Filament\AutoTranslator\Concerns\HasClusterTranslations
|
| Page |
RalphJSmit\Filament\AutoTranslator\Concerns\HasPageTranslations
|
| Resource |
RalphJSmit\Filament\AutoTranslator\Concerns\HasResourceTranslations
|
| Resource relation manager |
RalphJSmit\Filament\AutoTranslator\Concerns\HasResourceRelationManagerTranslations
|
| Resource page |
RalphJSmit\Filament\AutoTranslator\Concerns\HasResourcePageTranslations
|
| Widget |
RalphJSmit\Filament\AutoTranslator\Concerns\HasWidgetTranslations
|
| Exporter |
RalphJSmit\Filament\AutoTranslator\Concerns\HasExporterTranslations
|
| Importer |
RalphJSmit\Filament\AutoTranslator\Concerns\HasImporterTranslations
|
Example for an abstract base Resource class in your own project:
use Filament\Resources\Resource as BaseResource;
use RalphJSmit\Filament\AutoTranslator\Concerns\HasResourceTranslations;
use RalphJSmit\Filament\AutoTranslator\Contracts\HasTranslations;
abstract class Resource extends BaseResource implements HasTranslations
{
use HasResourceTranslations;
}
New projects
If you are starting a new project, you can either choose for all your resource/page/cluster/widget classes to extend the classes provided by this package, or to start creating an abstract base class for each of the objects that you extend. For example, look at the above Resource class example. In your project, every time you generate a new resource, you will need to make sure to extend the abstract base class that you created. Having an abstract base class can also be very beneficial in the future if you ever need to add any custom code that should apply to every resource/page/cluster/widget, then you already have a base class, which is a good Filament pattern.
Alternatively, it is also perfectly fine to not bother with abstract base classes but to just extend the classes by the AutoTranslator provided above.
Register the plugin
Next, you should register the plugin in each of the panels that you want to be translated:
use RalphJSmit\Filament\AutoTranslator\FilamentAutoTranslator;
$panel
->plugin(FilamentAutoTranslator::make())
Configuring the plugin per-panel
In the rest of the docs, if we refer to the $plugin variable, then we mean the $plugin = FilamentAutoTranslator::make(). This is not necessarily a variable, but it helps to keep the code examples shorter and simpler.
Therefore, the following code examples mean the same:
$plugin
->translationGroups([
// ...
]);
use RalphJSmit\Filament\AutoTranslator\FilamentAutoTranslator;
$panel
->plugin(
FilamentAutoTranslator::make()
->translationGroups([
// ...
])
)
Publishing translations
If wanted, you can publish the translations using the following command:
php artisan vendor:publish --tag="filament-auto-translator-translations"
Deployment environments
If you want to install the AutoTranslator during your GitHub Actions workflow, you can add the following line to your workflow file just before the composer install command:
composer config http-basic.satis.ralphjsmit.com ${{ secrets.FILAMENT_AUTO_TRANSLATOR_USERNAME }} ${{ secrets.FILAMENT_AUTO_TRANSLATOR_PASSWORD }}
composer install --no-interaction --prefer-dist --no-dev
Next, add the following two GitHub Actions secrets to your repository (Settings > Secrets and variables > Actions > New repository secret):
| Secret | Value |
|---|---|
| FILAMENT_AUTO_TRANSLATOR_USERNAME | Your e-mail |
| FILAMENT_AUTO_TRANSLATOR_PASSWORD | Your license key |
As Laravel Cloud does not support a global auth.json or a UI-based way to add private package credentials, the current solution is to add the following line to your deployment script, replacing {username} and {password} with your actual credentials:
composer config http-basic.satis.ralphjsmit.com {username} {password}
composer install --no-dev
Installing on Laravel Forge can be done in two ways. The simplest way is on first deploy to SSH to your server, run composer install, enter the required credentials and select yes when asked to save them in the global auth.json file. The other option is to go to {server} > PHP > Composer > Add credential in Forge. Here, enter the following details:
- Repository:
satis.ralphjsmit.com(note: do not prefix with https://) - Username: which is your e-mail
- Password: which is your license key
Changing the email associated with your license key
If you need to change the email associated with your license key, please send an e-mail to [email protected].
Changelog
You can view the changelog and/or subscribe for email updates on the Filament Plugins page. You can sign in using your license e-mail and a magic link, after which you can go to your plugin, click on the Gear icon > Changelog.