Write translations to database.

@return void
770996
protected function _write()
    {
        $paths = $this->_paths;
        $paths[] = realpath(APP) . DIRECTORY_SEPARATOR;

        usort($paths, function ($a, $b) {
            return strlen($a) - strlen($b);
        });

        $domains = null;
        if (!empty($this->params['domains'])) {
            $domains = explode(',', $this->params['domains']);
        }

        foreach ($this->_translations as $domain => $translations) {
            if (!empty($domains) && !in_array($domain, $domains)) {
                continue;
            }
            if ($this->_merge) {
                $domain = 'default';
            }
            foreach ($translations as $msgid => $contexts) {
                foreach ($contexts as $context => $details) {
                    $references = null;
                    if (!$this->param('no-location')) {
                        $files = $details['references'];
                        $occurrences = [];
                        foreach ($files as $file => $lines) {
                            $lines = array_unique($lines);
                            $occurrences[] = $file . ':' . implode(';', $lines);
                        }
                        $occurrences = implode("\n", $occurrences);
                        $occurrences = str_replace($paths, '', $occurrences);
                        $references = str_replace(DIRECTORY_SEPARATOR, '/', $occurrences);
                    }

                    $this->_save(
                        $domain,
                        $msgid,
                        $details['msgid_plural'] === false ? null : $details['msgid_plural'],
                        $context ?: null,
                        $references
                    );
                }
            }
        }
    }
691575
protected function generateGroupFiles(): void
    {
        foreach($this->languages as $language){
            foreach($this->translation_groups as $group){
                $file = $this->language_folder . $language . "\\" . $group->name . ".php";
                if(!file_exists($file)){
                    $new_file = fopen($file, "a");
                    fclose($new_file);
                    $this->info("Created translation group - $group->name - for language $language.");
                }
            }
        }
    }
608976
public function actionCreate()
    {
        $stdout = '';
        foreach ($this->db->schema->getTableSchemas() as $table) {
            if ($table->name === $this->migrationTable) {
                continue;
            }
            $stdout .= static::generateCreateTable($table->name).
                static::generateColumns($table->columns, $this->db->schema->findUniqueIndexes($table)).
                static::generatePrimaryKey($table->primaryKey, $table->columns).
                static::generateTableOptions();
        }
        foreach ($this->db->schema->getTableSchemas() as $table) {
            $stdout .= $this->generateForeignKey($table);
        }
        $this->stdout($stdout);
    }
1234538
public function registerTranslations()
	{
		$langPath = base_path('resources/lang/modules/course');

		if (is_dir($langPath)) {
			$this->loadTranslationsFrom($langPath, 'course');
		} else {
			$this->loadTranslationsFrom(__DIR__ .'/../Resources/lang', 'course');
		}
	}
1148669
public function saveTranslation()
    {
        $model = $this->getTranslation();
        $dirty = $model->getDirtyAttributes();
        if (empty($dirty)) {
            return true; // we do not need to save anything
        }
        /** @var \yii\db\ActiveQuery $relation */
        $relation = $this->owner->getRelation($this->relation);
        $model->{key($relation->link)} = $this->owner->getPrimaryKey();


        //Is translation valid?
        if (!$this->isTranslationActive($model)) {
            $this->deleteTranslation($model);
            return false;
        }

        return $model->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);
    }
1032387
def prepare_translations!
      stash.each do |locale, attrs|
        if attrs.any?
          translation = record.translations.find_by_locale(locale)
          translation ||= record.translations.build(:locale => locale)
          attrs.each{ |name, value| translation[name] = value }
        end
      end
      reset
    end
301011
public function up()
    {
        Schema::create('translator_translations', function ($table) {
            $table->increments('id');
            $table->string('locale', 6);
            $table->string('namespace')->default('*');
            $table->string('group');
            $table->string('item');
            $table->text('text');
            $table->boolean('unstable')->default(false);
            $table->boolean('locked')->default(false);
            $table->timestamps();
            $table->foreign('locale')->references('locale')->on('translator_languages');
            $table->unique(['locale', 'namespace', 'group', 'item']);
        });
    }
199764
public function Write()
    {
        file_put_contents(
            $this->file,
            \Peg\Lib\Utilities\Json::Encode($this->preferences)
        );
    }
1202192
public function writeToStorage($domain, $translations)
    {
        foreach ($translations as $keys) {
            foreach ($keys as $key => $transMeta) {
                $search = $this->repository->createSearch();
                $search->addQuery(new MatchQuery('key', $key));
                $results = $this->repository->findDocuments($search);
                if (count($results)) {
                    continue;
                }

                $document = new Translation();
                $document->setDomain($domain);
                $document->setKey($key);
                $document->setPath($transMeta['path']);
                $document->setFormat($transMeta['format']);
                foreach ($transMeta['messages'] as $locale => $text) {
                    $message = new Message();
                    $message->setLocale($locale);
                    $message->setMessage($text);
                    $document->addMessage($message);
                }
                $this->manager->persist($document);
            }
        }

        $this->manager->commit();
    }
698912
public function writeSQL($sql)
    {
        $this->sql = $sql;
        $this->PDO = $this->PDO->prepare($this->sql);
    }
541156
public function onLanguagesList()
    {
        $this->breadcrumbs->register('translations', function($breadcrumbs) {
            $breadcrumbs->push('Translations', handles('antares::translations/index/' . area()), ['force_link' => true]);
        });

        $this->shareOnView('translations');
    }
1160575
public function write($chars)
    {
        if (!isset($this->charReader)) {
            $this->charReader = $this->charReaderFactory->getReaderFor(
                $this->charset);
            $this->map = [];
            $this->mapType = $this->charReader->getMapType();
        }
        $ignored = '';
        $this->datas .= $chars;
        $this->charCount += $this->charReader->getCharPositions(substr($this->datas, $this->datasSize), $this->datasSize, $this->map, $ignored);
        if (false !== $ignored) {
            $this->datasSize = strlen($this->datas) - strlen($ignored);
        } else {
            $this->datasSize = strlen($this->datas);
        }
    }
735883
private function insertDefault() : void
    {
        // Insert default languages
        $this->batchInsert($this->table, [
            'slug', 'name',       'locale',     'alias',
            'icon', 'created_at', 'updated_at', 'created_by', 'updated_by'
        ],
        [
            ['ru', 'Русский', 'ru_RU', 'ru',  'ru', time(), time(), 1, 1],
            ['en', 'English', 'en_GB', 'en',  'gb', time(), time(), 1, 1],
        ]);
    }
589087
public function export()
    {
        $tableName = $this->db->quoteTableName($this->logTable);
        $sql = "INSERT INTO $tableName ([[level]], [[category]], [[log_time]], [[prefix]], [[message]])
                VALUES (:level, :category, :log_time, :prefix, :message)";
        $command = $this->db->createCommand($sql);
        foreach ($this->messages as $message) {
            list($text, $level, $category, $timestamp) = $message;
            if (!is_string($text)) {
                // exceptions may not be serializable if in the call stack somewhere is a Closure
                if ($text instanceof \Exception) {
                    $text = (string) $text;
                } else {
                    $text = VarDumper::export($text);
                }
            }
            $command->bindValues([
                ':level' => $level,
                ':category' => $category,
                ':log_time' => $timestamp,
                ':prefix' => $this->getMessagePrefix($message),
                ':message' => $text,
            ])->execute();
        }
    }
933165
private function ReadTranslations()
    {
        if (isset($this->translations[$this->language])) {
            return;
        }
        $this->translations[$this->language] = array();
        foreach ($this->basePaths as $basePath) {
            $handle = @fopen($this->LanguageCsvFile($basePath), 'r');
            if (!$handle) {
                return;
            }
            while ($line = fgetcsv($handle, 0, $this->delimiter, $this->enclosure)) {
                $this->ReadCsvLine($line);
            }
        }
    }
156616
public static function exportTranslations()
    {
        $translations = new Translations();
        $loc = Localization::getInstance();
        $loc->pushActiveContext(Localization::CONTEXT_SYSTEM);
        try {
            $app = Application::getFacadeApplication();
            $db = $app->make('database')->connection();
            $r = $db->executeQuery('select treeID from Trees order by treeID asc');
            while ($row = $r->fetch()) {
                try {
                    $tree = static::getByID($row['treeID']);
                } catch (Exception $x) {
                    $tree = null;
                }
                if (isset($tree)) {
                    /* @var $tree Tree */
                    $treeName = $tree->getTreeName();
                    if (is_string($treeName) && ($treeName !== '')) {
                        $translations->insert('TreeName', $treeName);
                    }
                    $rootNode = $tree->getRootTreeNodeObject();
                    /* @var $rootNode TreeNode */
                    if (isset($rootNode)) {
                        $rootNode->exportTranslations($translations);
                    }
                }
            }
        } catch (Exception $x) {
            $loc->popActiveContext();
            throw $x;
        }
        $loc->popActiveContext();

        return $translations;
    }