Download the PHP package filamerce/filament-translatable without Composer
On this page you can find all versions of the php package filamerce/filament-translatable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download filamerce/filament-translatable
More information about filamerce/filament-translatable
Files in filamerce/filament-translatable
Package filament-translatable
Short Description Highly customizable Translation component for FilamentPHP.
License MIT
Homepage https://github.com/filamerce/filament-translatable
Informations about the package filament-translatable
Filament Translatable
Filament Translatable is a set of tools that help manage translations.
Installation
Filament Version | Filament Translate Field Version |
---|---|
v4.x | v2.x |
v4.x | v3.x |
You can install the package via composer:
Publish the assets:
Configuration
With spatie/laravel-translatable
The package from Spatie is the default supported way of handling translations. Follow the instructions in the README to properly configure your models.
With astrotomic/laravel-translatable
The package from Astrotomic is an alternative supported way of handling translations.
Follow the instructions to properly configure your models, but instead of using the Translatable
trait from the Astrotomic package, please use Filamerce\FilamentTranslatable\Traits\AstrotomicTranslatable
.
If you use the Astrotomic package, please configure the plugin to work in Astrotomic mode:
You can also configure translationMode
per component:
Or per field:
Setup
Setting translatable locales
To set up the locales that can be used to translate content, pass an array of locales to the locales()
plugin method:
You can set locale labels using key => value array:
Also, you can pass a Closure:
Setting default locale
You can set the default locale using the defaultLocale()
method:
Enable or disable flags in locale labels
You can enable or disable flags in locale labels (disabled by default):
Setting flag width
You can set the flag width using:
Enable or disable names in locale labels
You can enable or disable locale names in locale labels (enabled by default):
Otherwise, the config value app.locale
will be used.
This affects several methods that can be used on fields.
Usage
translatable()
macro
By using the translatable()
macro, you can quickly configure a single form field to support multiple languages and provide translations for each locale.
Marking field as required for specified locale
This way, the "name" field will only be required in the "en" language.
Marking field as required for default locale
This way, the "name" field will only be required in the default language.
Decorating language specified fields
You can fully customize language-specific fields using the decorateTranslationField()
method.
Customizing Translations
component
After using the translatable()
method, the context of the field is switched to the Translations
component, so you can use any method that belongs to the component.
[!CAUTION] Be sure to set field-specific methods like
required()
orrequiredDefaultLocale()
before calling thetranslatable()
method.
Translations
component
By using the Translations
component, you can easily configure your form fields to support multiple languages and provide translations for each locale.
[!NOTE] Using the
translatable()
method within theTranslations
component is not needed.[!IMPORTANT] Be sure to set different names for each
Translations
component when using multiple instances.
Setting the translatable locales for a particular fields
By default, the translatable locales can be set globally for all translation form components in the plugin configuration. Alternatively, you can customize the translatable locales for a particular resource by overriding the locales()
method in the Translate
class:
Setting the translatable label for a particular field
You have the flexibility to customize the translation label for each field in each locale. You can use the fieldTranslatableLabel()
method to provide custom labels based on the field instance and the current locale.
Adding prefix/suffix locale label to the field
If you want to add a prefix or suffix locale label to the form field, you can use the prefixLocaleLabel()
or suffixLocaleLabel()
method. This makes it easier for users to identify the language associated with each field.
Setting the locale display name
By default, the prefix/suffix locale display name is generated from the locale code and enclosed in parentheses, "()". You may customize this using the preformLocaleLabelUsing()
method:
Injecting the current form field
Additionally, if you need to access the current form field instance, you can inject the $field
parameter into the callback functions. This allows you to perform specific actions or apply conditions based on the field being processed.
Adding action
You may add actions before each container of child components using the actions()
method:
Injecting the locale on current child container
If you wish to access the locale that has been passed to the action, define an $arguments
parameter and get the value of locale
from $arguments
:
Injecting the locale to form field
If you wish to access the current locale instance for the field, define a $locale
parameter:
Removing the styled container
By default, the translate component and its content are wrapped in a container styled as a card. You may remove the styled container using contained()
:
Vertical tabs
You can display translations as vertical tabs:
Changing plugin settings
You can customize plugin settings directly on the component:
Exclude
The exclude
feature allows you to specify fields that you don't want to include in the translation process. This can be useful for fields that contain dynamic content or that shouldn't be translated into other languages.
Without exclude
:
With exclude
:
Publishing Views
To publish the views, run:
Testing
Changelog
See the CHANGELOG for more information on what has changed recently.
Contributing
See CONTRIBUTING for details.
Security Vulnerabilities
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Credits
- Lipis for icons
- Solution Forest for great inspiration
- Outer Web for the macro idea
- All Contributors
License
Filament Translatable is open-sourced software licensed under the MIT license.