2017 © Pedro Peláez
 

symfony-bundle serializer-translation

Translation component for JMS Serializer

image

avoo/serializer-translation

Translation component for JMS Serializer

  • Monday, June 1, 2015
  • by avoo
  • Repository
  • 1 Watchers
  • 0 Stars
  • 16,672 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 3 Versions
  • 8 % Grown

The README.md

SerializerTranslation

Build Status Scrutinizer Code Quality Latest Stable Version License, (*1)

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

Installation

Require avoo/serializer-translation-bundle into your composer.json file:, (*3)

``` json { "require": { "avoo/serializer-translation-bundle": "@dev-master" } }, (*4)


Register the bundle in `app/AppKernel.php`: ``` php // app/AppKernel.php public function registerBundles() { return array( // ... new Avoo\SerializerTranslationBundle\AvooSerializerTranslationBundle(), ); }

Default Configuration

``` yaml, (*5)

app/config/config.yml

avoo_serializer_translation: metadata: cache: file file_cache: dir: %kernel.cache_dir%/avoo, (*6)



Default Usage ------------- For example, you want to translate `acme.foo.bar` from BDD. #### Default activation Into your translation file: ``` yaml # 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., (*7)

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:, (*8)

``` yaml, (*9)

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

acme: foo.bar: "welcome %foo%", (*10)


### XML ```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:, (*11)

License, (*12)

The Versions

01/06 2015

dev-master

9999999-dev

Translation component for JMS Serializer

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Jérémy Jégou

serializer translation

01/06 2015

0.1.1

0.1.1.0

Translation component for JMS Serializer

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Jérémy Jégou

serializer translation

01/09 2014

0.1

0.1.0.0

Translation component for JMS Serializer

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Jérémy Jégou

serializer translation