@param Translation[] $translations

@return string
978242
protected function createYml($translations)
    {
        $flatArray = array();
        foreach ($translations as $translation) {
            if ($translation->getValue() !== null) {
                $flatArray[$translation->getKey()] = $translation->getValue();
            }
        }

        return Yaml::dump($flatArray);
    }
649095
public function getTranslationsByLocalesAndDomains($locales, $domains)
    {
        $em = $this->getEntityManager();
        $qb = $em->createQueryBuilder();
        $qb
            ->select('t')
            ->from('KunstmaanTranslatorBundle:Translation', 't')
            ->andWhere('t.status != :statusstring')
            ->setParameter('statusstring', Translation::STATUS_DISABLED)
            ->orderBy('t.domain', 'ASC')
            ->addOrderBy('t.keyword', 'ASC');

        if (count($locales) > 0) {
            $qb->andWhere($qb->expr()->in('t.locale', $locales));
        }

        if (count($domains) > 0) {
            $qb->andWhere($qb->expr()->in('t.domain', $domains));
        }

        $result = $qb
            ->getQuery()
            ->getResult();

        return $result;
    }
1106682
public function convertArrayToCSV($translates)
    {
        $content = '';

        foreach ($translates as $key => $value) {
            $content .= $key.';'.$value."\n";
        }
        
        return $content;
    }
269949
function translate($str, $tokens = [])
    {
        if (array_key_exists($str, $this->translation)) {
            $str = $this->translation[$str];
        }
        if (is_array($tokens) && sizeof($tokens) > 0) {
            $str = vsprintf($str, $tokens);
        }

        return $str;
    }
930002
protected function _translate($matches)
    {
        $replacement = '';
        $translator = $this->getObject('translator');

        switch ($matches[0])
        {
            case 'D':
                $replacement = $translator->translate(strtoupper($this->_date->format('D')));
                break;

            case 'l':
                $replacement = $translator->translate(strtoupper($this->_date->format('l')));
                break;

            case 'F':
                $replacement = $translator->translate(strtoupper($this->_date->format('F')));
                break;

            case 'M':
                $replacement = $translator->translate(strtoupper($this->_date->format('F').'_SHORT'));
                break;
        }

        $replacement = preg_replace('/([a-z])/i', '\\\\$1', $replacement);

        return $replacement;
    }
269634
public function fillTranslations(Translations $translations)
    {
        $request = $this->buildRequest('fill-translations/po/')->setMethod('POST');
        $files = $request->getFiles();
        $files->set(
            'f',
            [
                'formname' => 'file',
                'filename' => 'translations.po',
                'ctype' => 'application/octet-stream',
                'data' => $translations->toPoString(),
            ]
        );
        unset($translations);
        $this->httpClient->reset();
        $response = $this->httpClient->send($request);
        $this->httpClient->reset();
        $responseBody = $response->getBody();
        if ($response->getStatusCode() >= 400) {
            throw new Exception($responseBody);
        }
        $translations = Translations::fromPoString($responseBody);

        return $translations;
    }
87159
private static function toArray(Translations $translations, $includeHeaders)
    {
        $messages = [];

        if ($includeHeaders) {
            $messages[''] = self::generateHeaders($translations);
        }

        foreach ($translations as $translation) {
            if ($translation->isDisabled()) {
                continue;
            }

            $messages[$translation->getOriginal()] = $translation->getTranslation();
        }

        return $messages;
    }
1091125
public static function translate_plural($string, Translation $translation = null) {
		if ($translation !== null) {
			$translation = self::get($translation->language, $translation->application_name);
		} else {
			$translation = self::get();
		}

		return $translation->translate_string($string);
	}
329716
protected function determinePath(array $languages): string
	{
		$path = '/';

		$server = $this->server->all();

		if(isset($server['PATH_INFO']))
		{
			$path = $server['PATH_INFO'];
		}
		elseif(isset($server['REQUEST_URI']))
		{
			if($path = parse_url($server['REQUEST_URI'], PHP_URL_PATH))
			{
				// Remove base path from the request path

				$basePath = pathinfo($server['SCRIPT_NAME'], PATHINFO_DIRNAME);

				if($basePath !== '/' && stripos($path, $basePath) === 0)
				{
					$path = mb_substr($path, mb_strlen($basePath));
				}

				// Remove "/index.php" from the path

				if(stripos($path, '/' . $this->scriptName) === 0)
				{
					$path = mb_substr($path, (strlen($this->scriptName) + 1));
				}

				$path = rawurldecode($path);
			}
		}

		return $this->stripLocaleSegment($languages, $path);
	}
797027
public static function generate(Translations $translations, array $options = [])
    {
        $options += static::$options;

        return self::toArray($translations, $options['includeHeaders'], true);
    }
232075
public function transform($translation)
    {
        $translation = $this->entityToArray(ContentTranslation::class, $translation);
        return [
            'id'             => (int) $translation['id'],
            'langCode'       => $translation['lang_code'],
            'title'          => $translation['title'],
            'teaser'         => $translation['teaser'],
            'body'           => $translation['body'],
            'seoTitle'       => $translation['seo_title'],
            'seoDescription' => $translation['seo_description'],
            'isActive'       => (bool) $translation['is_active'],
            'createdAt'      => $translation['created_at'],
            'updatedAt'      => $translation['updated_at'],
        ];
    }
973707
public function getRandomMissingTranslation(
        array $domains = [],
        array $languages = []
    ) : ? Translation {
        if (in_array($this->masterLanguage, $languages)) {
            throw new Exception('You cannot search by master language missing translations');
        }

        $candidates = [];
        $masterKeys = $this->getKeys(
            $domains,
            [$this->masterLanguage]
        );

        $languages = $languages ?: $this->getAvailableLanguages();

        foreach ($languages as $language) {
            $languageKeys = $this->getKeys(
                $domains,
                [$language]
            );

            $missingKeys = array_diff(
                $masterKeys,
                $languageKeys
            );
            foreach ($missingKeys as $missingKey) {
                $candidates[] = [
                    'language' => $language,
                    'key' => $missingKey,
                ];
            }
        }

        if (empty($candidates)) {
            return null;
        }

        $candidateKey = array_rand($candidates);
        $candidate = $candidates[$candidateKey];
        $masterCandidate = $this->getTranslation(
            $this->masterLanguage,
            $candidate['key']
        );

        $candidateTranslation = Translation::create(
            $candidate['key'],
            '',
            $candidate['language']
        );

        $candidateTranslation->setStructure($masterCandidate->getStructure());
        $candidateTranslation->setMasterTranslation($masterCandidate);

        return $candidateTranslation;
    }
454649
public function isValid($translations)
    {
        $this->message = null;

        // check if any translation contains restricted script tags
        $serializedStrings = serialize($translations);
        $invalids = array("<script", 'document.', 'javascript:', 'src=', 'background=', 'onload=');

        foreach ($invalids as $invalid) {
            if (stripos($serializedStrings, $invalid) !== false) {
                $this->message = 'script tags restricted for language files';
                return false;
            }
        }

        return true;
    }
865808
public function translateToRoleIds($roles)
    {
        if (!is_array($roles)) {
            if ($roles) {
                $roles = explode(",", $roles);
            } else {
                $roles = array();
            }
        }

        $lookup = array_flip($this->_roleTranslations);

        foreach ($roles as $key => $role) {
            if (isset($lookup[$role])) {
                $roles[$key] = $lookup[$role];
            }
        }

        return $roles;
    }
801282
protected function translations(array $files = array())
    {
        $return = [];
        foreach ($files as $file) {
            $translation = $this->getStringsBetween($file->getContents(), 'trans(\'', "')");
            $translation = array_filter($translation, function($element) {
                if (str_contains($element, ', {')) {
                    return false;
                }
                return $element;
            });
            $translationWithParams = $this->getStringsBetween($file->getContents(), 'trans(\'', "', {");
            $translation           = array_merge($translation, $translationWithParams);
            $return                = array_merge($return, $translation);
        }
        return $return;
    }
990992
public function labelPlural($translated = true)
    {
        if ($translated && $key = $this->getAttribute('translated_name_plural')) {
            if (($label = cms_trans($key)) !== $key) {
                return $label;
            }
        }

        return $this->getAttribute('verbose_name_plural');
    }
343966
protected function writeToFile(array $translations): void
    {
        $excel = app('excel');
        $filename = config('netcore.module-translate.translations_file');

        $excel
            ->create($filename, function (LaravelExcelWriter $writer) use ($translations) {
                $writer->setTitle('Translations');

                $writer->sheet('Translations', function (LaravelExcelWorksheet $sheet) use ($translations) {
                    $sheet->fromArray($translations, '', 'A1');

                    $sheet->row(1, function ($row) {
                        $row->setFontWeight('bold');
                    });
                });
            })
            ->store('xlsx', resource_path('seed_translations'));
    }