src/Graviton/I18nBundle/Serializer/Handler/TranslatableHandler.php
public function serializeTranslatableToJson(
        JsonSerializationVisitor $visitor,
        $translatable,
        array $type,
        Context $context
    ) {
        if (is_array($translatable) && empty($translatable)) {
            return $translatable;
        }

        $translations = $translatable->getTranslations();
        $defaultLanguage = $this->utils->getDefaultLanguage();
        if (isset($translations[$defaultLanguage]) && count($translations) != $this->utils->getLanguages()) {
            // languages missing
            $original = $translations[$defaultLanguage];
            $translated = $this->utils->getTranslatedField($original);

            $translatable->setTranslations(
                array_merge(
                    $translated,
                    $translatable->getTranslations()
                )
            );
        }

        return $translatable;
    }
public function serializeTranslatableToJson(
        JsonSerializationVisitor $visitor,
        $translatable,
        array $type,
        Context $context
    ) {
        if (is_array($translatable) && empty($translatable)) {
            return $translatable;
        }

        $translations = $translatable->getTranslations();
        $defaultLanguage = $this->utils->getDefaultLanguage();
        if (isset($translations[$defaultLanguage]) && count($translations) != $this->utils->getLanguages()) {
            // languages missing
            $original = $translations[$defaultLanguage];
            $translated = $this->utils->getTranslatedField($original);

            $translatable->setTranslations(
                array_merge(
                    $translated,
                    $translatable->getTranslations()
                )
            );
        }

        return $translatable;
    }
public function serializeTranslatableToJson ( JsonSerializationVisitor $ visitor , $ translatable , array $ type , Context $ context ) { if ( is_array ( $ translatable ) && empty ( $ translatable ) ) { return $ translatable ; } $ translations = $ translatable -> getTranslations ( ) ; $ defaultLanguage = $ this -> utils -> getDefaultLanguage ( ) ; if ( isset ( $ translations [ $ defaultLanguage ] ) && count ( $ translations ) != $ this -> utils -> getLanguages ( ) ) { // languages missing $ original = $ translations [ $ defaultLanguage ] ; $ translated = $ this -> utils -> getTranslatedField ( $ original ) ; $ translatable -> setTranslations ( array_merge ( $ translated , $ translatable -> getTranslations ( ) ) ) ; } return $ translatable ; }
Serialize Translatable to JSON

@param JsonSerializationVisitor $visitor      Visitor
@param Translatable             $translatable translatable
@param array                    $type         Type
@param Context                  $context      Context
@return string|null
Serialize Translatable to JSON