src/wcmf/lib/i18n/impl/DefaultLocalization.php
private function saveTranslatedValue(PersistentObject $object, $valueName, $existingTranslation, $lang) {
    $mapper = $object->getMapper();
    $isTranslatable = $mapper != null && $mapper->hasAttribute($valueName) ? $mapper->getAttribute($valueName)->hasTag('TRANSLATABLE') : false;
    if ($isTranslatable) {
      $value = $object->getValue($valueName);
      $translation = $existingTranslation;
      $valueIsEmpty = $value === null || $value === '';

      // if no translation exists and the value is not empty, create a new translation
      if ($translation == null && !$valueIsEmpty) {
        $translation = $this->persistenceFacade->create($this->translationType);
      }

      // if a translation exists and the value is empty, remove the existing translation
      if ($translation != null && $valueIsEmpty) {
        $translation->delete();
        $translation = null;
      }

      if ($translation) {
        // set all required properties
        $oid = $object->getOID()->__toString();
        $translation->setValue('objectid', $oid);
        $translation->setValue('attribute', $valueName);
        $translation->setValue('translation', $value);
        $translation->setValue('language', $lang);

        // store translation for oid update if necessary (see afterCreate())
        if (!isset($this->createdTranslations[$oid])) {
          $this->createdTranslations[$oid] = [];
        }
        $this->createdTranslations[$oid][] = $translation;
      }
    }
  }
private function saveTranslatedValue(PersistentObject $object, $valueName, $existingTranslation, $lang) {
    $mapper = $object->getMapper();
    $isTranslatable = $mapper != null && $mapper->hasAttribute($valueName) ? $mapper->getAttribute($valueName)->hasTag('TRANSLATABLE') : false;
    if ($isTranslatable) {
      $value = $object->getValue($valueName);
      $translation = $existingTranslation;
      $valueIsEmpty = $value === null || $value === '';

      // if no translation exists and the value is not empty, create a new translation
      if ($translation == null && !$valueIsEmpty) {
        $translation = $this->persistenceFacade->create($this->translationType);
      }

      // if a translation exists and the value is empty, remove the existing translation
      if ($translation != null && $valueIsEmpty) {
        $translation->delete();
        $translation = null;
      }

      if ($translation) {
        // set all required properties
        $oid = $object->getOID()->__toString();
        $translation->setValue('objectid', $oid);
        $translation->setValue('attribute', $valueName);
        $translation->setValue('translation', $value);
        $translation->setValue('language', $lang);

        // store translation for oid update if necessary (see afterCreate())
        if (!isset($this->createdTranslations[$oid])) {
          $this->createdTranslations[$oid] = [];
        }
        $this->createdTranslations[$oid][] = $translation;
      }
    }
  }
private function saveTranslatedValue ( PersistentObject $ object , $ valueName , $ existingTranslation , $ lang ) { $ mapper = $ object -> getMapper ( ) ; $ isTranslatable = $ mapper != null && $ mapper -> hasAttribute ( $ valueName ) ? $ mapper -> getAttribute ( $ valueName ) -> hasTag ( 'TRANSLATABLE' ) : false ; if ( $ isTranslatable ) { $ value = $ object -> getValue ( $ valueName ) ; $ translation = $ existingTranslation ; $ valueIsEmpty = $ value === null || $ value === '' ; // if no translation exists and the value is not empty, create a new translation if ( $ translation == null && ! $ valueIsEmpty ) { $ translation = $ this -> persistenceFacade -> create ( $ this -> translationType ) ; } // if a translation exists and the value is empty, remove the existing translation if ( $ translation != null && $ valueIsEmpty ) { $ translation -> delete ( ) ; $ translation = null ; } if ( $ translation ) { // set all required properties $ oid = $ object -> getOID ( ) -> __toString ( ) ; $ translation -> setValue ( 'objectid' , $ oid ) ; $ translation -> setValue ( 'attribute' , $ valueName ) ; $ translation -> setValue ( 'translation' , $ value ) ; $ translation -> setValue ( 'language' , $ lang ) ; // store translation for oid update if necessary (see afterCreate()) if ( ! isset ( $ this -> createdTranslations [ $ oid ] ) ) { $ this -> createdTranslations [ $ oid ] = [ ] ; } $ this -> createdTranslations [ $ oid ] [ ] = $ translation ; } } }
Save translated values for the given object
@param $object The object to save the translations on
@param $valueName The name of the value to translate
@param $existingTranslation Existing translation instance for the value (might be null).
@param $lang The language of the translations.
Save translated values for the given object