Available events | laravel-translatable-go | Spatie       

 SPATIE  

laravel-translatable-go
=======================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-translatable-go](https://spatie.be/docs/laravel-translatable-go/v1)  Advanced-usage  Available events

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-translatable-go/v1) 

  Available events    
- [ Introduction ](https://spatie.be/docs/laravel-translatable-go/v1/introduction)
- [ Requirements ](https://spatie.be/docs/laravel-translatable-go/v1/requirements)
- [ Upgrading ](https://spatie.be/docs/laravel-translatable-go/v1/upgrading)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-translatable-go/v1/installation-setup)
- [ Testing ](https://spatie.be/docs/laravel-translatable-go/v1/testing)
- [ Releasing ](https://spatie.be/docs/laravel-translatable-go/v1/releasing)
- [ Questions and issues ](https://spatie.be/docs/laravel-translatable-go/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-translatable-go/v1/changelog)
- [ Support us ](https://spatie.be/docs/laravel-translatable-go/v1/support-us)
- [ About us ](https://spatie.be/docs/laravel-translatable-go/v1/about-us)

Basic usage
-----------

- [ Getting and setting translations ](https://spatie.be/docs/laravel-translatable-go/v1/basic-usage/getting-and-settings-translations)
- [ Removing translations ](https://spatie.be/docs/laravel-translatable-go/v1/basic-usage/removing-translations)
- [ Replacing translations ](https://spatie.be/docs/laravel-translatable-go/v1/basic-usage/replacing-translations)
- [ Querying translations ](https://spatie.be/docs/laravel-translatable-go/v1/basic-usage/querying-translations)
- [ Validating translations ](https://spatie.be/docs/laravel-translatable-go/v1/basic-usage/validating-translations)
- [ Handling missing translations ](https://spatie.be/docs/laravel-translatable-go/v1/basic-usage/handling-missing-translations)

Advanced usage
--------------

- [ Available events ](https://spatie.be/docs/laravel-translatable-go/v1/advanced-usage/available-events)
- [ Customize the toArray method ](https://spatie.be/docs/laravel-translatable-go/v1/advanced-usage/customize-the-toarray-method)
- [ Usage with factories ](https://spatie.be/docs/laravel-translatable-go/v1/advanced-usage/usage-with-factories)

 Available events
================

Right after calling `SetTranslation`, a `translatable.TranslationHasBeenSetEvent` is dispatched through Laravel's event system. It contains the actual model and the key, locale, old value and new stored value:

```
type TranslationHasBeenSetEvent struct {
    Model              Model
    Key, Locale        string
    OldValue, NewValue any
}
```

Register listeners in your application's options:

```
Listeners: []laravel.Listener{
    laravel.Listen(func(ctx context.Context, e translatable.TranslationHasBeenSetEvent) error {
        slog.InfoContext(ctx, "Translation changed", "key", e.Key, "locale", e.Locale)
        return nil
    }),
},
```

A missing or null previous value is represented by an empty string. The new value has already passed the model's mutator. Bulk setters dispatch once per locale. Clearing an empty map does not dispatch. Removing a locale replays setters and events for retained locales.

Setters require an application context. Listener failures propagate and leave the model changed in memory. Events describe translation assignments, not database saves. Save the model explicitly afterward. Models remain live pointers in events, as in PHP. Copy any values you need for deferred work. No jobs are provided or required by this package.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
