Create translation file if not exists

@param string $absoluteTranslationFileName

@return array
182467
public static function generateTranslationsFile($absoluteTranslationFileName)
    {
        $translations = array();
        if (file_exists($absoluteTranslationFileName)) {
            @include($absoluteTranslationFileName);
        } else {
            Cache::getInstance()->storeData($absoluteTranslationFileName, "<?php \$translations = array();\n", Cache::TEXT, TRUE);
        }

        return $translations;
    }
217878
public function addTranslation(\Sulu\Bundle\ProductBundle\Entity\AttributeValueTranslation $translations)
    {
        $this->translations[] = $translations;

        return $this;
    }
888401
public function createTranslator()
    {
        return $this
            ->entityTranslatorFactory
            ->create(
                $this->entityTranslationProvider,
                $this->configuration,
                $this->fallback
            );
    }
808979
private function getTranslationFilesFromConfiguration($domain, $locale)
    {
        $filteredFilenames = array();

        foreach ($this->translationFilesByLocale as $localeFromConfig => $resourceFilePaths) {
            foreach ($resourceFilePaths as $filename) {
                list($currentDomain, $currentLocale) = explode('.', basename($filename), 3);

                if ($currentDomain === $domain && $currentLocale === $locale) {
                    $filteredFilenames[] = $filename;
                }
            }
        }
        return $filteredFilenames;
    }
851493
public function getOrCreateTranslationForLocale($locale)
    {
        foreach ($this->getTranslations() as $propelTranslation) {
            if ($propelTranslation->getLocale() == $locale) {
                return $propelTranslation;
            }
        }

        $propelTranslation = new PropelTranslation();
        $propelTranslation->setLocale($locale);
        $this->addTranslation($propelTranslation);

        return $propelTranslation;
    }
676534
private function importSingleTranslation($keyword, $text, $locale, $filename, $domain, $force = false)
    {
        if (strlen($keyword) > 255) {
            return false;
        }

        $translationGroup = $this->translationGroupManager->getTranslationGroupByKeywordAndDomain($keyword, $domain);

        if (!$translationGroup->hasTranslation($locale)) {
            $this->translationGroupManager->addTranslation($translationGroup, $locale, $text, $filename);

            return true;
        }

        if (true === $force) {
            $this->translationGroupManager->updateTranslation($translationGroup, $locale, $text, $filename);

            return true;
        }

        return false;
    }
1006623
protected function getTranslationOrNew($locale)
    {
        if (($translation = $this->getTranslation($locale)) === null) {
            $translation = $this->createNewTranslation($locale);
        }

        return $translation;
    }
847367
public function createTranslationForCurrentLocale($keyName, $value, $isActive = true)
    {
        return $this->glossaryFacade->createTranslationForCurrentLocale($keyName, $value, $isActive);
    }
562747
public function getTranslationFile()
    {
        $returnValue = null;

        
    	if ($this->translationFile != null) {
        	return $this->translationFile;
        }
        else {
        	throw new tao_helpers_translation_TranslationException('No TranslationFile to retrieve.');
        }
        

        return $returnValue;
    }
681644
public function getTranslator()
    {
        if ($this->translator === NULL) {
            $this->setTranslator(new Translations\FileTranslator);
        }

        return $this->translator;
    }
249298
public function parseTranslationFile() {
        $base_path = $this->getMinkParameter('files_path');
        $base_path = $base_path."/";
        $file_path = $base_path.$this->multilingual_parameters['translations'];
        $yaml = file_get_contents($file_path);
        $yaml_parse_array_check = Yaml::parse($yaml);
        if(is_array($yaml_parse_array_check)) {
            $this->translations = $yaml_parse_array_check;
        }
    }
909311
public function trans($toTranslate, $params = [], $forceLang = '')
    {
        $toTranslate = strtolower($toTranslate);
        $this->_getParams($toTranslate, $params);
        $toTranslate = trim($toTranslate);
        // If there isn't a dot we'll append one just to avoid the "undefined offset 1" warning
        if (false === strpos('.', $toTranslate)) {
            $toTranslate .= '.';
        }

        list($fileName, $key) = $this->parseFileKey($toTranslate);
        $langArray = $this->langFile($fileName, $forceLang);

        $value = isset($langArray[$key]) ? $langArray[$key] : $key;
        if (is_numeric(strpos($value, ':'))
            && !empty($params)
            && is_array($params)
        ) {
            $value = $this->_setParams($value, $params);
        }

        return $value;
    }
1373034
private function syncKeysBetweenLanguages($translationFiles)
    {
        $this->info('Synchronizing language files...');

        $filesResults = [];

        // Here we collect the file results
        foreach ($translationFiles as $fileName => $languageFiles) {
            foreach ($languageFiles as $languageKey => $filePath) {
                $filesResults[$fileName][$languageKey] = $this->manager->getFileContent($filePath);
            }
        }

        $values = Arr::dot($filesResults);

        $missing = $this->manager->getKeysExistingInALanguageButNotTheOther($values);

        foreach ($missing as &$missingKey) {
            list($file, $key) = explode('.', $missingKey, 2);

            list($key, $language) = explode(':', $key, 2);

            $this->fillMissingKeys($file, [$key], $language);
        }
    }
695960
public function getTranslationMessages($locale = 'en_EN', $textDomain = 'default')
    {
        // Get the translation service, so we would be able to fetch the current configs
        $translator = $this->getServiceLocator()->get('translator');
        $translation = $translator->getTranslator();
        $messages = array();

        // process to access the private properties of translation service
        $reflector = new \ReflectionObject($translation);
        $property = $reflector->getProperty('files');
        $property->setAccessible(true);
        $files = (array)$property->getValue($translation);

        if($files) {
            // re-add translation file to a new Translation Class Object
            if(isset($files['default']['*'])) {
                foreach($files['default']['*'] as $transKey => $transValues)
                {
                    $this->addTranslationFile('phparray', $transValues['filename'], 'default', $locale);
                }

                // Load Translation Messages
                if (!isset($this->messages[$textDomain][$locale])) {
                    $this->loadMessages($textDomain, $locale);
                }

                // This is where the translated mesage are stored
                $translatedMessages =  (array)$this->messages[$textDomain][$locale];


                $messages = array();
                $key = '';
                foreach($translatedMessages as $translationKey => $translationValues) {
                    $key =  str_replace("'", "\'", $translationKey);
                    $messages[$key] = str_replace("'", "\'", $translationValues);
                }
            }

        }



        return $messages;

    }
801469
public function getTranslations(): array
    {
        // Get english name
        $name = [
            'eng' => [
                'common' => $this->getName(),
                'official' => $this->getOfficialName(),
            ],
        ];

        // Get native names
        $natives = $this->getNativeNames() ?: [];

        // Get other translations
        $file = __DIR__.'/../resources/translations/'.mb_strtolower($this->getIsoAlpha2()).'.json';
        $translations = file_exists($file) ? json_decode(file_get_contents($file), true) : [];

        // Merge all names together
        $result = array_merge($translations, $natives, $name);

        // Sort alphabetically
        ksort($result);

        return $result;
    }
318311
public function load_translation()
    {
        $translator = new \Gettext\Translator();
        $i18n_path = realpath(__DIR__ . '/../../i18n/' . Config::$locale . '.po');

        if (file_exists($i18n_path)) {
            $translations = \Gettext\Translations::fromPoFile($i18n_path);
            $translator->loadTranslations($translations);
        }

        Translator::initGettextFunctions($translator);
    }
345599
protected function findTranslationsFiles($path, array $locales, array $domains, $autocompletePath = true)
    {
        $finder = null;

        if (preg_match('#^win#i', PHP_OS)) {
            $path = preg_replace('#'. preg_quote(DIRECTORY_SEPARATOR, '#') .'#', '/', $path);
        }

        if (true === $autocompletePath) {
            $dir = (0 === strpos($path, $this->getApplication()->getKernel()->getRootDir() . '/Resources')) ? $path : $path . '/Resources/translations';
        } else {
            $dir = $path;
        }

        $this->output->writeln('<info>*** Using dir ' . $dir . ' to lookup translation files. ***</info>');

        if (is_dir($dir)) {
            $finder = new Finder();
            $finder->files()
                ->name($this->getFileNamePattern($locales, $domains))
                ->in($dir);
        }

        return (null !== $finder && $finder->count() > 0) ? $finder : null;
    }