Skip to main content

Crate laravel_translatable

Crate laravel_translatable 

Source
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 HasTranslations for a model, listing its translatable fields as PHP’s $translatable property does. Each field is a Translations or an Option<Translations>:

Structs§

AttributeIsNotTranslatable
The attribute isn’t one of the model’s translatable attributes: AttributeIsNotTranslatable.
MissingKeyCallback
A callback that runs when a translation is missing, as the PHP package’s missingKeyCallback. Returning Some(text) replaces the translation; returning None keeps it.
MissingTranslation
What the missing-key callback is told when a translation is missing for the requested locale: the arguments of PHP’s missingKeyCallback.
TranslatableConfig
The package’s settings, the properties of the PHP package’s Translatable class, plus the application locales it reads from config/app.php:
TranslatableServiceProvider
Registers the TranslatableConfig section. Its methods are those of PHP’s Translatable class, 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 HasTranslations trait.
TranslationsField
A field that holds translations: Translations, or Option<Translations> for a nullable column. The translatable! macro uses it, so you don’t implement it.

Functions§

locale
The current locale: the one set_locale set for this request, job, or command, or else APP_LOCALE. Laravel’s App::getLocale(), which the PHP package reads as config('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 column for locale compares to value with operand (=, !=, <>, <, <=, >, >= or like): whereJsonContainsLocale.
where_json_contains_locales
Rows whose translation of column for any of locales compares to value: whereJsonContainsLocales.
where_locale
Rows with a translation of column for locale: whereLocale.
where_locales
Rows with a translation of column for any of locales: whereLocales.
where_translation_like
Rows whose translation of any of columns, in any of locales, contains search, ignoring case: whereTranslationLike. Without locales, the configured locales are searched, or the current locale when none are configured. As in PHP, % and _ in search are wildcards. No columns or no locales match nothing.

Type Aliases§

AllTranslations
The translations of every translatable attribute, by attribute and then by locale.