PHPackages                             symfonycasts/object-translation-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Localization &amp; i18n](/categories/localization)
4. /
5. symfonycasts/object-translation-bundle

ActiveSymfony-bundle[Localization &amp; i18n](/categories/localization)

symfonycasts/object-translation-bundle
======================================

Translate your entities!

v1.1.0(5mo ago)5403MITPHPPHP &gt;=8.2CI passing

Since Nov 22Pushed 5mo agoCompare

[ Source](https://github.com/SymfonyCasts/object-translation-bundle)[ Packagist](https://packagist.org/packages/symfonycasts/object-translation-bundle)[ RSS](/packages/symfonycasts-object-translation-bundle/feed)WikiDiscussions 1.x Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (3)Used By (0)

symfonycasts/object-translation-bundle
======================================

[](#symfonycastsobject-translation-bundle)

This bundle provides a simple way to translate Doctrine entities in Symfony applications.

Installation
------------

[](#installation)

### Install the bundle via Composer:

[](#install-the-bundle-via-composer)

```
composer require symfonycasts/object-translation-bundle
```

### Enable the bundle in your `config/bundles.php` file:

[](#enable-the-bundle-in-your-configbundlesphp-file)

Note

This step is not required if you are using Symfony Flex.

```
return [
    // ...
    ObjectTranslationBundle::class => ['all' => true],
];
```

### Create the translation entity in your app:

[](#create-the-translation-entity-in-your-app)

Note

This step is not required if you are using Symfony Flex.

```
namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use SymfonyCasts\ObjectTranslationBundle\Model\Translation as BaseTranslation;

#[ORM\Entity]
class Translation extends BaseTranslation
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    public int $id;
}
```

### Configure the entity in your `config/packages/object_translation.yaml` file:

[](#configure-the-entity-in-your-configpackagesobject_translationyaml-file)

Note

This step is not required if you are using Symfony Flex.

```
symfonycasts_object_translation:
    translation_class: App\Entity\Translation
```

### Create and run the migration to add the translation table:

[](#create-and-run-the-migration-to-add-the-translation-table)

```
symfony console make:migration
symfony console doctrine:migrations:migrate
```

Marking Entities as Translatable
--------------------------------

[](#marking-entities-as-translatable)

To mark an entity as translatable, use the `Translatable` attribute on the entity class and the `TranslatableProperty` attribute on the fields you want to translate.

```
namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use SymfonyCasts\ObjectTranslationBundle\Mapping\Translatable;
use SymfonyCasts\ObjectTranslationBundle\Mapping\TranslatableProperty;

#[ORM\Entity]
#[Translatable('product')]
class Product
{
    // ...

    #[ORM\Column(type: 'string', length: 255)]
    #[TranslatableProperty]
    public string $name;

    #[ORM\Column(type: 'text')]
    #[TranslatableProperty]
    public string $description;
}
```

Usage
-----

[](#usage)

### `ObjectTranslator` Service

[](#objecttranslator-service)

You can inject the `ObjectTranslator` service to translate entities.

```
use SymfonyCasts\ObjectTranslationBundle\ObjectTranslator;

class ProductController
{
    public function show(Product $product, ObjectTranslator $objectTranslator)
    {
        // translate into the current request locale
        $translatedProduct = $objectTranslator->translate($product);

        $translatedProduct->getName(); // returns the translated name (if available)
        $translatedProduct->getDescription(); // returns the translated description (if available)

        // ...
    }
}
```

The second argument of the `translate()` method allows you to specify a locale:

```
$product = $objectTranslator->translate($product, 'fr'); // translates into French
```

### `translate_object` Twig Filter

[](#translate_object-twig-filter)

If using Twig, you can use the `translate_object` filter to translate entities directly in templates.

```
{% set translatedProduct = product|translate_object %} {# translates into the current request locale #}

{% set frenchProduct = product|translate_object('fr') %} {# translates into French #}
```

Managing Translations
---------------------

[](#managing-translations)

The `Translation` database table has the following structure:

- `id`: Primary key (added by you)
- `object_type`: The *alias* defined in the `Translatable` attribute (e.g., `product`)
- `object_id`: The ID of the translated entity
- `locale`: The locale of the translation (e.g., `fr`)
- `field`: The entity property name being translated (e.g., `description`)
- `value`: The translated value

Each row represents a single property translation for a specific entity in a specific locale.

You can manage these translations yourself but two console commands are provided to help:

### `object-translation:export`

[](#object-translationexport)

This command exports all entity translations, in your default locale, to a CSV file.

```
symfony console object-translation:export translations.csv
```

This will create a `translations.csv` file at the root of your project with the following structure:

```
type,id,field,value
```

You can then take this file to translation service for translation. Be sure to keep the `type`, `id`, and `field` columns intact. The `value` column is what needs to be translated into the desired language.

### `object-translation:import`

[](#object-translationimport)

This command imports translations from a CSV file created by the `export` command after the `value` column has been translated.

```
symfony console object-translation:import translations_fr.csv fr
```

The first argument is the path to the CSV file, and the second argument is the locale of the translations in that file.

Translation Caching
-------------------

[](#translation-caching)

For performance, translations are cached. By default, they use your `cache.app` pool and have no expiration time. This can be configured:

```
symfonycasts_object_translation:
    cache:
        pool: 'cache.object_translation' # a custom pool name
        ttl: 3600 # expire after one hour
```

### Translation Tags

[](#translation-tags)

If your cache pool supports *cache tagging*, tags are added to the cache keys. Two keys are added:

- `object-translation`: All translations are tagged with this key.
- `object-translation-{type}`: Where `{type}` is the translatable alias (e.g., `product`).

You can invalidate these tags by using the `cache:pool:invalidate-tags` command:

```
# invalidate all object translation caches
symfony console cache:pool:invalidate-tags object-translation

# invalidate only the translation cache for "product" entities
symfony console cache:pool:invalidate-tags object-translation-product
```

### `object-translation:warmup` Command

[](#object-translationwarmup-command)

This command preloads all translations into the cache for all your app's enabled locales.

```
symfony console object-translation:warmup
```

Full Default Configuration
--------------------------

[](#full-default-configuration)

```
symfonycasts_object_translation:

    # The class name of your translation entity.
    translation_class:    ~ # Required, Example: App\Entity\Translation

    # Cache settings for object translations.
    cache:
        enabled:              true

        # The cache pool to use for storing object translations.
        pool:                 cache.app

        # The time-to-livefor cached translations, in seconds, null for no expiration.
        ttl:                  null
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance73

Regular maintenance activity

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 50% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~13 days

Total

3

Last Release

150d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/707369cc916e0ea1aacbf077dcba464f611cef879f024d8944311a54a15224b3?d=identicon)[kbond](/maintainers/kbond)

---

Top Contributors

[![kbond](https://avatars.githubusercontent.com/u/127811?v=4)](https://github.com/kbond "kbond (3 commits)")[![tacman](https://avatars.githubusercontent.com/u/619585?v=4)](https://github.com/tacman "tacman (2 commits)")[![gbere](https://avatars.githubusercontent.com/u/1327334?v=4)](https://github.com/gbere "gbere (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/symfonycasts-object-translation-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/symfonycasts-object-translation-bundle/health.svg)](https://phpackages.com/packages/symfonycasts-object-translation-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-bundle)[lexik/translation-bundle

This bundle allows to import translation files content into the database and provide a GUI to edit translations.

4362.7M19](/packages/lexik-translation-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[kimai/kimai

Kimai - Time Tracking

4.6k7.4k1](/packages/kimai-kimai)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
