---
title: "Translations — Advertisements for Laravel | Roundly"
description: "Name, description and slug are per-locale JSON maps with active-locale reads, a configurable fallback and no third-party dependency."
url: https://roundly-consulting.com/open-source/docs/advertisements-for-laravel/translations
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Advertisements for Laravel](https://roundly-consulting.com/open-source/docs/advertisements-for-laravel.md)

# Translations

name, description and slug are per-locale JSON maps via the in-package Concerns\\HasTranslations trait — no third-party dependency. Reading resolves the active locale, then fallback\_locale, then any stored value:

```php
$ad->setTranslation('name', 'de', 'Vintage Fahrrad')->save();

app()->setLocale('de');
$ad->name;                          // "Vintage Fahrrad"
$ad->getTranslation('name', 'en');  // "Vintage Bike"
$ad->getTranslations('name');       // ['en' => 'Vintage Bike', 'de' => 'Vintage Fahrrad']
```

Assigning a bare string ($ad->name = 'Bike') stores it under the current locale, so single-locale code keeps working. When neither the active nor the fallback locale has a value, the lowest-sorted locale wins — the same result on PostgreSQL, MySQL and SQLite.

## Full API

```php
$ad->setTranslations('description', ['en' => 'Lightly used.', 'sk' => 'Málo používaný.'])->save();
$ad->hasTranslation('name', 'sk');              // bool — exact locale, no fallback
$ad->forgetTranslation('name', 'de')->save();

$ad->name = 'Road bike';                        // stored under the active locale only
```

- getTranslation($attribute, ?$locale) — one locale, with the fallback chain.
- getTranslations($attribute) — the whole locale => value map.
- setTranslation() / setTranslations() — write one locale or replace the map; both chain.
- forgetTranslation() — drop one locale.
- hasTranslation($attribute, ?$locale) — whether that exact locale has a value.

Placements and categories translate their name the same way. A new locale in an ad’s name also gets its own slug (see Slugs & routing).

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/advertisements-for-laravel.md)
