Expand description
Translatable model attributes for Laravel Rust: a port of spatie/laravel-translatable.
Translations are stored as JSON, {"en":"Hello","nl":"Hallo"}, exactly as the PHP package
stores them, so a database shared with a PHP application reads the same. See the
README for the guide.
Modules§
- events
- The package’s event:
Spatie\Translatable\Events\TranslationHasBeenSetEvent.
Macros§
- translatable
- Implements
HasTranslationsfor a model, listing its translatable fields as PHP’s$translatableproperty does. Each field is aTranslationsor anOption<Translations>:
Structs§
- Attribute
IsNot Translatable - The attribute isn’t one of the model’s translatable attributes:
AttributeIsNotTranslatable. - Missing
KeyCallback - A callback that runs when a translation is missing, as the PHP package’s
missingKeyCallback. ReturningSome(text)replaces the translation; returningNonekeeps it. - Missing
Translation - What the missing-key callback is told when a translation is missing for the requested locale:
the arguments of PHP’s
missingKeyCallback. - Translatable
Config - The package’s settings, the properties of the PHP package’s
Translatableclass, plus the application locales it reads fromconfig/app.php: - Translatable
Service Provider - Registers the
TranslatableConfigsection. Its methods are those of PHP’sTranslatableclass, which applications call in a service provider: - Translations
- The translations of one attribute, by locale, stored as a JSON object exactly as the PHP
package stores it:
{"en":"Hello","nl":"Hallo"}.
Traits§
- HasTranslations
- A model with translatable attributes: the PHP package’s
HasTranslationstrait. - Translations
Field - A field that holds translations:
Translations, orOption<Translations>for a nullable column. Thetranslatable!macro uses it, so you don’t implement it.
Functions§
- locale
- The current locale: the one
set_localeset for this request, job, or command, or elseAPP_LOCALE. Laravel’sApp::getLocale(), which the PHP package reads asconfig('app.locale'). - set_
locale - Sets the current locale for the rest of the request, job, or command, as Laravel’s
App::setLocale(). A middleware is a good place to call it: - where_
json_ contains_ locale - Rows whose translation of
columnforlocalecompares tovaluewithoperand(=,!=,<>,<,<=,>,>=orlike):whereJsonContainsLocale. - where_
json_ contains_ locales - Rows whose translation of
columnfor any oflocalescompares tovalue:whereJsonContainsLocales. - where_
locale - Rows with a translation of
columnforlocale:whereLocale. - where_
locales - Rows with a translation of
columnfor any oflocales:whereLocales. - where_
translation_ like - Rows whose translation of any of
columns, in any oflocales, containssearch, ignoring case:whereTranslationLike. Withoutlocales, the configuredlocalesare searched, or the current locale when none are configured. As in PHP,%and_insearchare wildcards. No columns or no locales match nothing.
Type Aliases§
- AllTranslations
- The translations of every translatable attribute, by attribute and then by locale.