PHPackages                             hostnet/entity-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. hostnet/entity-translation-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

hostnet/entity-translation-bundle
=================================

Translation bundle to help with rendering pretty names for enum-like classes.

1.0.10(1y ago)597.7k↓13.2%7[1 issues](https://github.com/hostnet/entity-translation-bundle/issues)MITPHPPHP ^8.1CI passing

Since Sep 26Pushed 1y ago4 watchersCompare

[ Source](https://github.com/hostnet/entity-translation-bundle)[ Packagist](https://packagist.org/packages/hostnet/entity-translation-bundle)[ RSS](/packages/hostnet-entity-translation-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (11)Versions (18)Used By (0)

entity-translation-bundle
=========================

[](#entity-translation-bundle)

This bundle allows the automation of translating an enum value to a human readable string, for example, displaying a status text instead of the enum-value of a status code.

In it's essence, it allows to map a value to a translation within the domain that is the class name. What this means in practice is that you can use it as follows:

```
$status_text = $translator->trans(SetupStatus::DONE, [], SetupStatus::class);
```

Or in a twig template:

```
{{ constant('AppBundle\\Entity\\SetupStatus::DONE') | trans([], 'AppBundle\\Entity\\SetupStatus') }}
```

Requirements
------------

[](#requirements)

The entity translation bundle requires at least php 7.3 and the symfony translation component. For specific requirements, please check [composer.json](../master/composer.json)

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

[](#installation)

Installing is pretty straightforward, this package is available on [packagist](https://packagist.org/packages/hostnet/entity-translation-bundle).

#### Example

[](#example)

```
$ composer require hostnet/entity-translation-bundle

```

#### Register The Bundle in your AppKernel

[](#register-the-bundle-in-your-appkernel)

This bundle makes use of the translator which is registered by the framework bundle. So make sure you register this bundle after the `FrameworkBundle`.

```
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new AppBundle\AppBundle(),
            new Hostnet\Bundle\EntityTranslationBundle\HostnetEntityTranslationBundle(),
            // ...
        ];

        return $bundles;
    }
}
```

Usage
-----

[](#usage)

Simply add an `enum.en.yml` to the translations folder in the Resources folder of one of your bundles. This will contain the translations for a given enum. The translation keys are the fully qualified namespaces in lowercase and an `_` between CamelCase words. So for instance the enum `AppBundle\Entity\SetupStatus` would become `app_bundle.entity.setup_status`.

Consider the following class:

```
