Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Serializer Translation Laravel Package

avoo/serializer-translation

View on GitHub
Deep Wiki
Context7

SerializerTranslation

[![Build Status] (https://scrutinizer-ci.com/g/avoo/SerializerTranslation/badges/build.png?b=master)](https://scrutinizer-ci.com/g/avoo/SerializerTranslation/build-status/master) [![Scrutinizer Code Quality] (https://scrutinizer-ci.com/g/avoo/SerializerTranslation/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/avoo/SerializerTranslation/?branch=master) ![Latest Stable Version] (https://poser.pugx.org/avoo/serializer-translation/v/stable.svg) ![License] (https://poser.pugx.org/avoo/serializer-translation/license.svg)

This is a PHP library based on JMS Serializer, and add translation option configuration for any properties.

Installation

Require avoo/serializer-translation-bundle into your composer.json file:

{
    "require": {
        "avoo/serializer-translation-bundle": "@dev-master"
    }
}

Register the bundle in app/AppKernel.php:

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Avoo\SerializerTranslationBundle\AvooSerializerTranslationBundle(),
    );
}

Default Configuration

# app/config/config.yml

avoo_serializer_translation:
    metadata:
        cache:                file
        file_cache:
            dir:              %kernel.cache_dir%/avoo

Default Usage

For example, you want to translate acme.foo.bar from BDD.

Default activation

Into your translation file:

# Acme/DemoBundle/Resources/translations/messages.en.yml

acme:
    foo.bar: "Welcome."
<?xml version="1.0" encoding="UTF-8" ?>
<serializer>
    <class name="Acme\DemoBundle\Entity\Sample" exclusion-policy="ALL" xml-root-name="sample" xmlns:a="https://github.com/avoo/SerializerTranslationBundle">
        <property name="property" expose="true" type="string">
            <a:translate />
        </property>
    </class>
</serializer>

YAML

Acme\DemoBundle\Entity\Sample:
    exclusion_policy: ALL
    xml_root_name: sample
    properties:
        property:
            expose: true
            type: string
            translate: true

Annotations

Important: The annotation need to be defined.

use Avoo\SerializerTranslation\Configuration\Annotation as AvooSerializer;

/**
 * @var string $property
 *
 * @AvooSerializer\Translate()
 */
 protected $property;

Json output sample

{
    "property": "welcome."
}

With custom parameters

With custom parameters

Into your translation file:

# Acme/DemoBundle/Resources/translations/messages.en.yml

acme:
    foo.bar: "welcome %foo%"

XML

<?xml version="1.0" encoding="UTF-8" ?>
<serializer>
    <class name="Acme\DemoBundle\Entity\Sample" exclusion-policy="ALL" xml-root-name="sample" xmlns:a="https://github.com/avoo/SerializerTranslationBundle">
        <property name="property" expose="true" type="string">
            <a:translate domain="messages" locale="en">
                <a:parameter name="%foo%" value="expr(object.getProperty())" />
            </a:translate>
        </property>
    </class>
</serializer>

YAML

Acme\DemoBundle\Entity\Sample:
    exclusion_policy: ALL
    xml_root_name: sample
    properties:
        property:
            expose: true
            type: string
            translate:
                parameters:
                    %foo%: expr(object.getProperty())
                locale: en
                domain: messages

Annotations

use Avoo\SerializerTranslation\Configuration\Annotation as AvooSerializer;

/**
 * @var string $property
 *
 * @AvooSerializer\Translate(
 *     parameters = {
 *         "%foo%" = "expr(object.getProperty())"
 *     },
 *     domain = "messages",
 *     locale = "en"
 * )
 */
 protected $property;

Json output sample

{
    "property": "welcome Superman",
}

License

This bundle is released under the MIT license. See the complete license in the bundle:

License

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor