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

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

locastic/api-platform-translation-bundle
========================================

Translation bundle for Api platform based on Sylius translation

v1.4.1(5mo ago)83458.3k↑30.6%32[13 issues](https://github.com/Locastic/ApiPlatformTranslationBundle/issues)[3 PRs](https://github.com/Locastic/ApiPlatformTranslationBundle/pulls)MITPHPPHP &gt;=8.4CI passing

Since Sep 24Pushed 5mo ago8 watchersCompare

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

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

Locastic Api Translation Bundle
 [ ![](https://camo.githubusercontent.com/6ddc97b05888a7e79d0181526177d2adafa37646ad2494d5922db240c9ed0164/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6f6361737469632f6170692d706c6174666f726d2d7472616e736c6174696f6e2d62756e646c652e737667) ](https://packagist.org/packages/locastic/api-platform-translation-bundle "License") [ ![](https://camo.githubusercontent.com/2b3da573870fbd031c0d8ac1c0350513fa7596daf5f20b48f44a96d9cad6f85f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f4c6f6361737469632f6170692d706c6174666f726d2d7472616e736c6174696f6e2d62756e646c652e737667) ](https://packagist.org/packages/locastic/api-platform-translation-bundle "Version") [ ![](https://camo.githubusercontent.com/53a5737b9004f189a2b457decf39a8237f278aaaee96fa8c6262161131f61c20/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4c6f6361737469632f417069506c6174666f726d5472616e736c6174696f6e42756e646c652f6d61737465722e737667) ](https://travis-ci.org/Locastic/ApiPlatformTranslationBundle "Build status") [ ![](https://camo.githubusercontent.com/8e2488238ec033682f3a61cf2f79593667276a0ba3c4326a10fe57934ebf2219/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4c6f6361737469632f417069506c6174666f726d5472616e736c6174696f6e42756e646c652e737667) ](https://scrutinizer-ci.com/g/Locastic/ApiPlatformTranslationBundle/ "Scrutinizer") [ ![](https://camo.githubusercontent.com/14cbea337f2e7728382c32cdc00dcedd0f8fd365d8ebf6df40883ee71ef11510/68747470733a2f2f706f7365722e707567782e6f72672f6c6f6361737469632f6170692d706c6174666f726d2d7472616e736c6174696f6e2d62756e646c652f646f776e6c6f616473) ](https://packagist.org/packages/locastic/api-platform-translation-bundle "Total Downloads")
============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#locastic-api-translation-bundle--------------------------------------------------------------------------------)

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

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

[](#installation)

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

```

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

[](#implementation)

**Translatable entity:**

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

```
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Locastic\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 Locastic\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 Locastic\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 `Locastic\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 Locastic\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"
        }
    }
}
```

Contribution
------------

[](#contribution)

If you have idea on how to improve this bundle, feel free to contribute. If you have problems or you found some bugs, please open an issue.

Support
-------

[](#support)

Want us to help you with this bundle or any Api Platform/Symfony project? Write us an email on

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance70

Regular maintenance activity

Popularity52

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 51.6% 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 ~165 days

Recently: every ~289 days

Total

17

Last Release

151d ago

PHP version history (5 changes)v1.0PHP ^7.1

v1.2.4PHP ^7.2.5

v1.3.4PHP ^8.0

v1.4PHP ^8.1

v1.4.1PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/13758a6abd53618188475ebd3bab831a8669a3ebe7f9880a12a2ec1ba80b9643?d=identicon)[antonioperic](/maintainers/antonioperic)

---

Top Contributors

[![paullla](https://avatars.githubusercontent.com/u/6206691?v=4)](https://github.com/paullla "paullla (32 commits)")[![antonioperic](https://avatars.githubusercontent.com/u/2453151?v=4)](https://github.com/antonioperic "antonioperic (5 commits)")[![jewome62](https://avatars.githubusercontent.com/u/472429?v=4)](https://github.com/jewome62 "jewome62 (5 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)")[![k-37](https://avatars.githubusercontent.com/u/60838818?v=4)](https://github.com/k-37 "k-37 (1 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)")[![nirav-programmer](https://avatars.githubusercontent.com/u/421466?v=4)](https://github.com/nirav-programmer "nirav-programmer (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)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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