Saves attribute data to different language (eg. english).

@return null
176960
public function saveinnlang()
    {
        parent::save();

        $soxId = $this->getEditObjectId();
        $aParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");

        $oAttr = oxNew(\OxidEsales\Eshop\Application\Model\Attribute::class);

        if ($soxId != "-1") {
            $oAttr->loadInLang($this->_iEditLang, $soxId);
        } else {
            $aParams['oxattribute__oxid'] = null;
        }

        //Disable editing for derived items
        if ($oAttr->isDerived()) {
            return;
        }

        $oAttr->setLanguage(0);
        $oAttr->assign($aParams);

        // apply new language
        $oAttr->setLanguage(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("new_lang"));
        $oAttr->save();

        // set oxid if inserted
        $this->setEditObjectId($oAttr->getId());
    }
313672
private function retrieveAttributeValueTranslationByLocale(AttributeValue $attributeValue, $locale)
    {
        foreach ($attributeValue->getTranslations() as $attributeValueTranslation) {
            if ($attributeValueTranslation->getLocale() === $locale) {
                return $attributeValueTranslation;
            }
        }

        return null;
    }
961237
private function migrateDataFromLegacyFormat(){

        if(count($this->trees) > 0){

            //tree attributes to be migrated.
           $mapping = array(
              'editClassUrl' => array(
                'attr'   => 'selectClass',
                'action' => array(
                    'id'      => 'edit_class',
                    'name'    => 'edit class',
                    'group'   => 'none',
                    'context' => 'class',
                    'binding' => 'load'
                ) 
              ),
              'editInstanceUrl' => array(
                'attr'   => 'selectInstance',
                'action' => array(
                    'id'      => 'edit_instance',
                    'name'    => 'edit instance',
                    'group'   => 'none',
                    'context' => 'instance',
                    'binding' => 'load'
                ) 
              ),
              'addInstanceUrl'  => array(
                'attr'   => 'addInstance',
                'action' => array(
                    'id'      => 'add_instance',
                    'name'    => 'add instance',
                    'group'   => 'none',
                    'context' => 'instance',
                    'binding' => 'instantiate'
                ) 
              ),
              'addSubClassUrl'  => array(
                'attr'   => 'addClass',
                'action' => array(
                    'id'      => 'add_class',
                    'name'    => 'add class',
                    'group'   => 'none',
                    'context' => 'class',
                    'binding' => 'subClass'
                ) 
              ),
              'deleteUrl' => array(
                'attr'   => 'addClass',
                'action' => array(
                    'id'      => 'add_class',
                    'name'    => 'add class',
                    'group'   => 'none',
                    'context' => 'class',
                    'binding' => 'subClass'
                ) 
              ),
              'moveInstanceUrl' => array(
                'attr'   => 'moveInstance',
                'action' => array(
                    'id'      => 'move',
                    'name'    => 'move',
                    'group'   => 'none',
                    'context' => 'instance',
                    'binding' => 'moveNode'
                ) 
              )
           );

           foreach($this->trees as $index => $tree){
               $needMigration = false;
               $treeAttributes = $tree->getAttributes();
            
               //check if this attribute needs a migration
               foreach($treeAttributes as $attr){
                    if(array_key_exists($attr, $mapping)){
                        $needMigration = true;
                        break;
                    } 
               }
               if($needMigration){
                    $newData = array();

                    //migrate the tree
                    foreach($treeAttributes as $attr){
                        //if the attribute belongs to the mapping
                        if(array_key_exists($attr, $mapping)){
                            $url = $tree->get($attr);
                            $actionName = false;
    
                            //try to find an action with the same url
                            foreach($this->actions as $action){
                                if($action->getRelativeUrl() == $url){
                                    $actionName = $action->getId();
                                    break;
                                }
                            }
                            if($actionName){
                                $newData[$mapping[$attr]['attr']] = $actionName;
                            } else {
    
                                //otherwise create a new action from the mapping
                                $newData[$mapping[$attr]['attr']] = $mapping[$attr]['action']['id'];
                                $actionData = $mapping[$attr]['action'];
                                $actionData['url'] = $url;
                                
                                list($extension, $controller, $action) = explode('/', trim($url, '/'));
                                $actionData['extension'] = $extension;
                                $actionData['controller'] = $controller;
                                $actionData['action'] = $action;
                                
                                $this->actions[] = new Action($actionData); 
                            }
                        } else {
                            $newData[$attr] = $tree->get($attr);
                        }
                    }
    
                    //the tree is replaced
                    $this->trees[$index] = new Tree($newData);
               }
           }
        }
    }
367097
function setOriginalAttributeDataFromAttribute( $contentObjectAttribute )
    {
        $originalImageHandler = $contentObjectAttribute->attribute( 'content' );
        $originalAttributeData = $originalImageHandler->originalAttributeData();
        $domTree = $originalImageHandler->domTree();
        $this->setDOMTree( $domTree );
        if ( $originalAttributeData['attribute_id'] )
        {
            $this->setOriginalAttributeData( $originalAttributeData );
        }
        else
        {
            $this->setOriginalAttributeDataValues( $contentObjectAttribute->attribute( 'id' ),
                                                   $contentObjectAttribute->attribute( 'version' ),
                                                   $contentObjectAttribute->attribute( 'language_code' ) );
        }
    }
1326684
public function saveI18N()
    {
        if (empty($this->i18n_data)) return;
        $this->i18n_relation()->getQuery()->whereIn($this->getI18NCodeField(), array_keys($this->i18n_data))->delete();
        foreach ($this->i18n_data as $locale => $data) {
            $obj                             = new $this->i18n_class();
            $data[$this->i18n_primary]       = $this->id;
            $data[$this->getI18NCodeField()] = $locale;
            $obj->create($data);
        }
    }
782525
public function change()
    {
        $tableName = 'language_translations';
        if (!$this->hasTable($tableName)) {
            $tableName = 'translations';
        }
        $table = $this->table($tableName);
        if ($table->hasColumn('is_active')) {
            $table->removeColumn('is_active');
        }
        if ($table->hasColumn('code')) {
            $table->removeColumn('code');
        }
        if ($table->hasColumn('language_id')) {
            $table->changeColumn('language_id', 'string', [
                'limit' => 36,
                'null' => false,
            ]);
        } else {
            $table->addColumn('language_id', 'string', [
                'limit' => 36,
                'null' => false,
            ]);
        }
        $table->save();
    }
784830
public function save()
    {
        $keys = array_keys($this->langstrings);
        sort($keys);

        $maxlen       = 0;
        $langPrefixes = array();
        foreach ($keys as $key) {
            $tokens = explode('.', $key);
            if (preg_match('/tl_layout\.[a-z]+\.css\./', $key)) {
                $tokens = array($tokens[0], $tokens[1] . '.' . $tokens[2], $tokens[3]);
            }
            $langPrefix = '$GLOBALS[\'TL_LANG\']';
            foreach ($tokens as $token) {
                $langPrefix .= '[\'' . $token . '\']';
            }

            $langPrefixes[$key] = $langPrefix;

            if (strlen($langPrefix) > $maxlen) {
                $maxlen = strlen($langPrefix);
            }
        }

        $buffer = $this->getHead() . PHP_EOL . PHP_EOL;
        foreach ($keys as $key) {
            $prefix  = $langPrefixes[$key];
            $buffer .= sprintf(
                '%s = %s;' . PHP_EOL,
                $prefix . str_repeat(' ', ($maxlen - strlen($prefix))),
                var_export($this->getValue($key), true)
            );
        }
        $buffer  .= PHP_EOL;
        $resource = fopen($this->filename, 'wb');
        fputs($resource, $buffer);

        fclose($resource);
    }
660959
private function saveLanguage() {
        if ($this->_saveOnCookies) {
            $this->getRequiredModules('cookies')->setCookie($this->_cookieName, $this->_selectedLanguage, 30 * 24);
        }
        if ($this->_saveOnSession) {
            $_SESSION[$this->_sessionKeyName] = $this->_selectedLanguage;
            $_SESSION['default_language'] = $this->_defaultLang;
        }
    }
1035280
public function getLocalLabel($attribute, $language = null)
    {
        if ($language === null) {
            $language = \Yii::$app->language;
        }
        /** @var ActiveRecord $owner */
        $owner = $this->owner;
        if ($owner->isNewRecord) {
            return $owner->getAttribute($attribute);
        }
        $localLabels = $this->getLocalLabels();

        return !isset($localLabels[$language][$owner->getPrimaryKey()][$attribute])
            ? $owner->getAttribute($attribute)
            : $localLabels[$language][$owner->getPrimaryKey()][$attribute];
    }
203394
public function setTranslatedAttribute($attribute, $alias = null)
    {
        if ($alias) {
            $this->translatedAliasAttribute[$alias] = $attribute;
        } else {
            $this->translatedAttribute = $attribute;
        }
    }
551271
protected function _initTranslate()
    {
        $this->bootstrap('locale');

        $language = $this->locale->getLanguage();

        /*
         * Scan for files with -<languagecode> and disable notices when the requested
         * language is not found
         */
        $options = array( 'adapter'         => 'gettext',
                          'content'         => GEMS_LIBRARY_DIR . '/languages/',
                          'disableNotices'  => true,
                          'scan'            => \Zend_Translate::LOCALE_FILENAME);

        $translate = new \Zend_Translate($options);

        // If we don't find the needed language, use a fake translator to disable notices
        if (! $translate->isAvailable($language)) {
            $translate = \MUtil_Translate_Adapter_Potemkin::create();
        }

        //Now if we have a project specific language file, add it
        $projectLanguageDir = APPLICATION_PATH . '/languages/';
        if (file_exists($projectLanguageDir)) {
            $options['content']        = $projectLanguageDir;
            $options['disableNotices'] = true;
            $projectTranslations       = new \Zend_Translate($options);
            //But only when it has the requested language
            if ($projectTranslations->isAvailable($language)) {
                $translate->addTranslation(array('content' => $projectTranslations));
            }
            unset($projectTranslations);  //Save some memory
        }

        $translate->setLocale($language);
        \Zend_Registry::set('Zend_Translate', $translate);

        // Fix for _init resource being case insensitive
        $container = $this->getContainer();
        $adapter   = $translate->getAdapter();
        $container->translateAdapter = $adapter;
        $this->translateAdapter      = $adapter;

        return $translate;
    }
1216120
public function filterI18NColumn()
    {
        $overrideData = array_only($this->attributes, $this->i18n_fillable);
        if (!empty($overrideData)) {
            $this->i18n_data[$this->i18n_default_locale] = $overrideData;
            foreach ($this->i18n_fillable as $key) {
                unset($this->$key);
            }
        }

        if (isset($this->attributes[$this->i18n_attribute_name])) {
            $this->i18n_data = $this->attributes[$this->i18n_attribute_name];
            unset($this->attributes[$this->i18n_attribute_name]);
        }
    }
1343686
public function saveinnlang()
    {
        $soxId = $this->getEditObjectId();
        $aParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");
        // checkbox handling
        if (!isset($aParams['oxlinks__oxactive'])) {
            $aParams['oxlinks__oxactive'] = 0;
        }

        $oLinks = oxNew(\OxidEsales\Eshop\Application\Model\Links::class, getViewName('oxlinks'));
        $iEditLanguage = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editlanguage");

        if ($soxId != "-1") {
            $oLinks->loadInLang($iEditLanguage, $soxId);
        } else {
            $aParams['oxlinks__oxid'] = null;
            //$aParams = $oLinks->ConvertNameArray2Idx( $aParams);
        }

        //Disable editing for derived items
        if ($oLinks->isDerived()) {
            return;
        }

        $oLinks->setLanguage(0);
        $oLinks->assign($aParams);

        // apply new language
        $oLinks->setLanguage(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("new_lang"));
        $oLinks->save();

        // set oxid if inserted
        $this->setEditObjectId($oLinks->getId());
    }
24176
protected function InitLanguageFile()
    {
        if ($this->language == null)
            $this->language = new Language();

        $this->InitRecLanguageFile(get_class($this));
    }
248660
public function save()
    {
        $result = true;

        if (!empty($this->changedData)) {
            foreach ($this->changedData as $scope => $rowData) {
                foreach ($rowData as $layoutName => $layoutData) {
                    if (empty($scope) || empty($layoutName)) {
                        continue;
                    }
                    $layoutPath = $this->getLayoutPath($scope, true);
                    $data = Json::encode($layoutData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);

                    $result &= $this->getFileManager()->putContents(array($layoutPath, $layoutName.'.json'), $data);
                }
            }
        }

        if ($result == true) {
            $this->clearChanges();
        }

        return (bool) $result;
    }
906888
public function attributes(): array
    {
        $languages = TransHelper::getAllLanguages();
        $translatedAttributes = ['name', 'slug'];

        $placeholder = 'for language ":lang"';

        if ($languages->count() == 1) {
            $language = $languages->first();

            return [
                "translations.{$language->iso_code}.name" => '',
                "translations.{$language->iso_code}.slug" => '',
            ];
        }

        $attributes = [];

        foreach ($translatedAttributes as $translatedAttribute) {
            foreach ($languages as $language) {
                $replaced = str_replace(':lang', $language->title_localized, $placeholder);
                $attributes["translations.{$language->iso_code}.{$translatedAttribute}"] = $replaced;
            }
        }

        return $attributes;
    }
661817
def write_attribute(name, value, options = {})
      if translated?(name)
        options = {:locale => nil}.merge(options)
        access = name.to_s
        unless attributes[access] == value || attribute_changed?(access)
          attribute_will_change! access
        end
        @translated_attributes[access] = value
        the_locale = options[:locale] || Mongoid::Globalize.locale
        self.translations.reject!{ |t| t.new_record? && t.locale != the_locale } if self.class.fallbacks_for_empty_translations
        globalize.write(the_locale, name, value)
      else
        super(name, value)
      end
    end