PHPackages                             sarcinae/api-platform-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. sarcinae/api-platform-translation-bundle

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

sarcinae/api-platform-translation-bundle
========================================

Translation bundle for Api platform based on Sylius translation

v1.5.2(7mo ago)021MITPHPPHP ^8.1

Since Oct 8Pushed 7mo agoCompare

[ Source](https://github.com/Sarcinae/ApiPlatformTranslationBundle)[ Packagist](https://packagist.org/packages/sarcinae/api-platform-translation-bundle)[ RSS](/packages/sarcinae-api-platform-translation-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (6)Versions (4)Used By (0)

Translation bundle for [ApiPlatform](https://api-platform.com/) based on [Sylius translation](https://docs.sylius.com/en/1.2/book/architecture/translations.html)

This is the fork of [Locastic Api Translation Bundle](https://github.com/Locastic/ApiPlatformTranslationBundle) updated for ApiPlatform 4.0

Installation:
-------------

[](#installation)

```
$ composer require sarcinae/api-platform-translation-bundle

```

Implementation:
---------------

[](#implementation)

**Translatable entity:**

- Extend your model/resource with `Sarcinae\ApiTranslationBundle\Model\AbstractTranslatable`
- Add `createTranslation()` method which returns new object of translation Entity. Example:

```
use Sarcinae\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Sarcinae\ApiPlatformTranslationBundle\Model\TranslationInterface;

class Post extends AbstractTranslatable
{
    // ...

    protected function createTranslation(): TranslationInterface
    {
        return new PostTranslation();
    }
}
```

- Add a `translations`-property. Add the `translations` serializations group and make a connection to the translation entity:

```
use Sarcinae\ApiPlatformTranslationBundle\Model\AbstractTranslatable;

class Post extends AbstractTranslatable
{
    // ...

    /**
     * @ORM\OneToMany(targetEntity="PostTranslation", mappedBy="translatable", fetch="EXTRA_LAZY", indexBy="locale", cascade={"PERSIST"}, orphanRemoval=true)
     *
     * @Groups({"post_write", "translations"})
     */
    protected $translations;
}
```

- Add virtual fields for all translatable fields, and add read serialization group. Getters and setters must call getters and setters from translation class. Example:

```
use Sarcinae\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Symfony\Component\Serializer\Annotation\Groups;

class Post extends AbstractTranslatable
{
    // ...

    /**
    * @Groups({"post_read"})
    */
    private $title;

    public function setTitle(string $title)
    {
        $this->getTranslation()->setTitle($title);
    }

    public function getTitle(): ?string
    {
        return $this->getTranslation()->getTitle();
    }
}
```

**Translation entity:**

- Add entity with all translatable fields. Name needs to be name of translatable entity + Translation
- Extend `Sarcinae\ApiPlatformTranslationBundle\Model\AbstractTranslation`
- Add serialization group `translations` to all fields and other read/write groups. Example Translation entity:

```
use Symfony\Component\Serializer\Annotation\Groups;
use Sarcinae\ApiPlatformTranslationBundle\Model\AbstractTranslation;

class PostTranslation extends AbstractTranslation
{
    // ...

    /**
     * @ORM\ManyToOne(targetEntity="Post", inversedBy="translations")
     */
    protected $translatable;

    /**
     * @ORM\Column(type="string")
     *
     * @Groups({"post_read", "post_write", "translations"})
     */
    private $title;

    /**
     * @ORM\Column(type="string")
     *
     * @Groups({"post_write", "translations"})
     */
    protected $locale;

    public function setTitle(string $title): void
    {
        $this->title = $title;
    }

    public function getTitle(): ?string
    {
        return $this->title;
    }
}
```

**Api resource**

- Add `translation.groups` filter if you would like to have option to return all translation objects in response. If you don't use `translations` group, response will return only requested locale translation or fallback locale translation.
- Add translations to normalization\_context for PUT and POST methods to make sure they return all translation objects.
- Example:

```
AppBundle\Entity\Post:
    itemOperations:
        get:
            method: GET
        put:
            method: PUT
            normalization_context:
                groups: ['translations']
    collectionOperations:
        get:
            method: GET
        post:
            method: POST
            normalization_context:
                groups: ['translations']
    attributes:
        filters: ['translation.groups']
        normalization_context:
            groups: ['post_read']
        denormalization_context:
            groups: ['post_write']
```

Usage:
------

[](#usage)

**Language param for displaying single translation:**

`?locale=de`

**Or use Accept-Language http header**

`Accept-Language: de`

**Serialization group for displaying all translations:**

`?groups[]=translations`

**POST translations example**

```
{
    "datetime":"2017-10-10",
    "translations": {
        "en":{
            "title":"test",
            "content":"test",
            "locale":"en"
        },
        "de":{
            "title":"test de",
            "content":"test de",
            "locale":"de"
        }
    }
}
```

**EDIT translations example**

```
{
    "datetime": "2017-10-10T00:00:00+02:00",
    "translations": {
        "de": {
          "id": 3,
          "title": "test edit de",
          "content": "test edit de",
          "locale": "de"
        },
        "en": {
          "id": 2,
          "title": "test edit",
          "content": "test edit",
          "locale": "en"
        }
    }
}
```

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance64

Regular maintenance activity

Popularity7

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~0 days

Total

3

Last Release

221d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/07367b7b696807663d125320c698038117686154d6db9e99dc40ad1f77961c10?d=identicon)[Sarcinae](/maintainers/Sarcinae)

---

Top Contributors

[![paullla](https://avatars.githubusercontent.com/u/6206691?v=4)](https://github.com/paullla "paullla (32 commits)")[![jewome62](https://avatars.githubusercontent.com/u/472429?v=4)](https://github.com/jewome62 "jewome62 (5 commits)")[![antonioperic](https://avatars.githubusercontent.com/u/2453151?v=4)](https://github.com/antonioperic "antonioperic (5 commits)")[![Sarcinae](https://avatars.githubusercontent.com/u/14262488?v=4)](https://github.com/Sarcinae "Sarcinae (4 commits)")[![alanpoulain](https://avatars.githubusercontent.com/u/10920253?v=4)](https://github.com/alanpoulain "alanpoulain (4 commits)")[![guillaume-sainthillier](https://avatars.githubusercontent.com/u/5052984?v=4)](https://github.com/guillaume-sainthillier "guillaume-sainthillier (2 commits)")[![konradkozaczenko](https://avatars.githubusercontent.com/u/57705320?v=4)](https://github.com/konradkozaczenko "konradkozaczenko (1 commits)")[![luca-nardelli](https://avatars.githubusercontent.com/u/6215162?v=4)](https://github.com/luca-nardelli "luca-nardelli (1 commits)")[![Margauxfeslard](https://avatars.githubusercontent.com/u/48242659?v=4)](https://github.com/Margauxfeslard "Margauxfeslard (1 commits)")[![Oipnet](https://avatars.githubusercontent.com/u/13480665?v=4)](https://github.com/Oipnet "Oipnet (1 commits)")[![pascal-zarrad](https://avatars.githubusercontent.com/u/14060618?v=4)](https://github.com/pascal-zarrad "pascal-zarrad (1 commits)")[![pgrimaud](https://avatars.githubusercontent.com/u/1866496?v=4)](https://github.com/pgrimaud "pgrimaud (1 commits)")[![samnela](https://avatars.githubusercontent.com/u/1852108?v=4)](https://github.com/samnela "samnela (1 commits)")[![SpartakusMd](https://avatars.githubusercontent.com/u/438308?v=4)](https://github.com/SpartakusMd "SpartakusMd (1 commits)")[![Alex--C](https://avatars.githubusercontent.com/u/5671931?v=4)](https://github.com/Alex--C "Alex--C (1 commits)")[![ArnoudThibaut](https://avatars.githubusercontent.com/u/14937343?v=4)](https://github.com/ArnoudThibaut "ArnoudThibaut (1 commits)")[![CoalaJoe](https://avatars.githubusercontent.com/u/5689499?v=4)](https://github.com/CoalaJoe "CoalaJoe (1 commits)")[![gonzaloalonsod](https://avatars.githubusercontent.com/u/1031176?v=4)](https://github.com/gonzaloalonsod "gonzaloalonsod (1 commits)")[![k-37](https://avatars.githubusercontent.com/u/60838818?v=4)](https://github.com/k-37 "k-37 (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sarcinae-api-platform-translation-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/sarcinae-api-platform-translation-bundle/health.svg)](https://phpackages.com/packages/sarcinae-api-platform-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)[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)[sulu/sulu

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

1.3k1.3M152](/packages/sulu-sulu)[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)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

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