/**
  * Adds a new translation and creates a new dedicated fieldset.
  * If $lang is an invalid locale (ie. malformed or not declared in site.ini/RegionalSettings.Locale), will throw a SQLIContentException
  * @param string $lang Translation code to add, as a locale (xxx-XX)
  * @throws SQLIContentException
  */
 public function addTranslation($lang)
 {
     $language = eZContentLanguage::fetchByLocale($lang, true);
     if (!$language instanceof eZContentLanguage) {
         throw new SQLIContentException("Invalid language '{$lang}'. Must be a valid locale declared in site.ini, RegionalSettings.Locale !");
     }
     $db = eZDB::instance();
     $db->begin();
     $version = $this->getCurrentDraft($lang);
     $versionNumber = $version->attribute('version');
     $objectID = $this->contentObject->attribute('id');
     $translatedDataMap = $this->contentObject->fetchDataMap($versionNumber, $lang);
     // Check if data map exists for this language in the current draft
     // Indeed, several translations can be created for only one publication of an object
     if (!$translatedDataMap) {
         $classAttributes = $this->contentObject->fetchClassAttributes();
         foreach ($classAttributes as $classAttribute) {
             // TODO : Check if attribute is translatable
             $classAttribute->instantiate($objectID, $lang, $versionNumber);
         }
         // Now clears in-memory cache for this datamap (it was fetched once above)
         // Then re-fetch the newly created translated data map
         global $eZContentObjectDataMapCache;
         unset($eZContentObjectDataMapCache[$objectID][$versionNumber][$lang]);
         unset($this->contentObject->ContentObjectAttributes[$versionNumber][$lang]);
         unset($this->contentObject->DataMap[$versionNumber][$lang]);
         $translatedDataMap = $this->contentObject->fetchDataMap($versionNumber, $lang);
     }
     $version->setAttribute('initial_language_id', $language->attribute('id'));
     $version->updateLanguageMask();
     $version->store();
     $db->commit();
     $set = SQLIContentFieldset::fromDataMap($translatedDataMap);
     $set->setLanguage($lang);
     $this->fieldsets[$lang] = $set;
     $this->initIterator();
 }
 /**
  * Initializes a fieldset from a content object data map
  * @param array $dataMap
  * @return SQLIContentFieldset
  */
 public static function fromDataMap(array $dataMap)
 {
     $set = new SQLIContentFieldset();
     foreach ($dataMap as $key => $attribute) {
         $set->setContentObjectAttribute($attribute);
     }
     $set->initIterator();
     return $set;
 }