Initialize the ts translator and context if this is not already done

@param string $context
@param string $locale
@param string $filename
@param bool $useCache
@return eZTSTranslator
429877
static function initialize( $context, $locale, $filename, $useCache = true )
    {
        $instance = false;
        $file = $locale . '/' . $filename;
        if ( !empty( $GLOBALS['eZTSTranslationTables'][$file] ) )
        {
            $instance = $GLOBALS['eZTSTranslationTables'][$file];
            if ( $instance->hasInitializedContext( $context ) )
            {
                return $instance;
            }
        }

        eZDebug::createAccumulatorGroup( 'tstranslator', 'TS translator' );
        eZDebug::accumulatorStart( 'tstranslator_init', 'tstranslator', 'TS init' );
        if ( !$instance )
        {
            $instance = new eZTSTranslator( $locale, $filename, $useCache );
            $GLOBALS['eZTSTranslationTables'][$file] = $instance;
            $manager = eZTranslatorManager::instance();
            $manager->registerHandler( $instance );
        }
        $instance->load( $context );
        eZDebug::accumulatorStop( 'tstranslator_init' );
        return $instance;
    }
1172374
public static function translateContext(string $context, string $message, ...$args): string
    {
        $message = self::$translator->translateContext($context, $message);

        return sprintf($message, ...$args);
    }
408846
public function getCachedJson(Locale $locale)
    {
        $cacheIdentifier = md5($locale);

        if ($this->xliffToJsonTranslationsCache->has($cacheIdentifier)) {
            $json = $this->xliffToJsonTranslationsCache->get($cacheIdentifier);
        } else {
            $labels = [];

            foreach ($this->packagesRegisteredForAutoInclusion as $packageKey => $sourcesToBeIncluded) {
                if (!is_array($sourcesToBeIncluded)) {
                    continue;
                }

                $package = $this->packageManager->getPackage($packageKey);
                $sources = $this->collectPackageSources($package, $sourcesToBeIncluded);

                //get the xliff files for those sources
                foreach ($sources as $sourceName) {
                    $fileId = $packageKey . ':' . $sourceName;
                    $file = $this->xliffFileProvider->getFile($fileId, $locale);

                    foreach ($file->getTranslationUnits() as $key => $value) {
                        $valueToStore = !empty($value[0]['target']) ? $value[0]['target'] : $value[0]['source'];
                        if ($this->scrambleTranslatedLabels) {
                            $valueToStore = str_repeat('#', UnicodeFunctions::strlen($valueToStore));
                        }
                        $this->setArrayDataValue($labels, str_replace('.', '_', $packageKey) . '.' . str_replace('/', '_', $sourceName) . '.' . str_replace('.', '_', $key), $valueToStore);
                    }
                }
            }

            $json = json_encode($labels);
            $this->xliffToJsonTranslationsCache->set($cacheIdentifier, $json);
        }

        return $json;
    }
529014
public function _get($condition = "1=1", $include = false, $useCache = false) {
		try {
			$condition = $this->getCondition ( $condition );
			$include = $this->getInclude ( $include );
			$useCache = UString::isBooleanTrue ( $useCache );
			$datas = DAO::getAll ( $this->model, $condition, $include, null, $useCache );
			echo $this->_getResponseFormatter ()->get ( $datas );
		} catch ( \Exception $e ) {
			$this->_setResponseCode ( 500 );
			echo $this->_getResponseFormatter ()->formatException ( $e );
		}
	}
1117526
public function getTranslatedProperty($property, $locale, $prefix = null)
    {
        return new TranslatedProperty($property, $locale, $this->languageNamespace, $prefix);
    }
308103
public function initWriter( $locale )
    {
        $this->dom = $this->openTranslationFileForWriting( $locale );
        $this->writeLocale = $locale;
    }
1241633
public function get_tables($usecache=true) {
        if ($usecache and $this->tables !== null) {
            return $this->tables;
        }
        $this->tables = array();
        $prefix = str_replace('_', "\\_", strtoupper($this->prefix));
        $sql = "SELECT TABLE_NAME
                  FROM CAT
                 WHERE TABLE_TYPE='TABLE'
                       AND TABLE_NAME NOT LIKE 'BIN\$%'
                       AND TABLE_NAME LIKE '$prefix%' ESCAPE '\\'";
        $this->query_start($sql, null, SQL_QUERY_AUX);
        $stmt = $this->parse_query($sql);
        $result = oci_execute($stmt, $this->commit_status);
        $this->query_end($result, $stmt);
        $records = null;
        oci_fetch_all($stmt, $records, 0, -1, OCI_ASSOC);
        oci_free_statement($stmt);
        $records = array_map('strtolower', $records['TABLE_NAME']);
        foreach ($records as $tablename) {
            if ($this->prefix !== false && $this->prefix !== '') {
                if (strpos($tablename, $this->prefix) !== 0) {
                    continue;
                }
                $tablename = substr($tablename, strlen($this->prefix));
            }
            $this->tables[$tablename] = $tablename;
        }

        // Add the currently available temptables
        $this->tables = array_merge($this->tables, $this->temptables->get_temptables());

        return $this->tables;
    }
836884
static function treeCacheFilename( $key, $templateFilepath )
    {
        $internalCharset = eZTextCodec::internalCharset();
        $extraName = '';
        if ( preg_match( "#^.+/(.*)\.tpl$#", $templateFilepath, $matches ) )
            $extraName = '-' . $matches[1];
        else if ( preg_match( "#^(.*)\.tpl$#", $templateFilepath, $matches ) )
            $extraName = '-' . $matches[1];
        $cacheFileKey = "$key-$internalCharset";
        $cacheFileName = md5( $cacheFileKey ) . $extraName . '.php';
        return $cacheFileName;
    }
625150
public function useCacheIfPossible($useCache = true)
    {
        if ($useCache && is_readable($this->cacheFileName)) {
            $fileTime   = filemtime($this->pathToImage);
            $cacheTime  = filemtime($this->cacheFileName);

            if ($fileTime <= $cacheTime) {
                if ($this->useCache) {
                    if ($this->verbose) {
                        $this->log("Use cached file.");
                        $this->log("Cached image filesize: " . filesize($this->cacheFileName) . " bytes.");
                    }
                    $this->output($this->cacheFileName, $this->outputFormat);
                } else {
                    $this->log("Cache is valid but ignoring it by intention.");
                }
            } else {
                $this->log("Original file is modified, ignoring cache.");
            }
        } else {
            $this->log("Cachefile does not exists or ignoring it.");
        }

        return $this;
    }
687474
public function getSerializedTranslations(PackageVersionEntity $packageVersion, LocaleEntity $locale, TranslationsConverter $format)
    {
        $file = $this->getSerializedTranslationsFile($packageVersion, $locale, $format);

        $result = $this->fs->get($file);
        if ($result === false) {
            throw new UserMessageException(t('Failed to read a cache file'));
        }

        return $result;
    }
632275
public function set($langcode, $context)
    {
        $result = null;
        $this->hook->attach('translation.set.before', $langcode, $context, $result, $this);

        if (isset($result)) {
            return $result;
        }

        $this->setContext($context);
        $this->setLangcode($langcode);

        $result = $this->prepareFiles($langcode);

        $this->hook->attach('translation.set.after', $langcode, $context, $result, $this);
        return (bool) $result;
    }
941920
public function setLocale($locale = null, $remember = false)
    {
        $this->_locale->setLocale($locale);
        $t = $this->getTranslator();
        if ($t->isAvailable($this->_locale))
            $t->setLocale($this->_locale);
        if ($remember) $this->_session->locale = $this->_locale->toString();
    }
781872
public function loadSource($locale, $group, $namespace = '*')
    {
        if ($this->cache->has($locale, $group, $namespace)) {
            return $this->cache->get($locale, $group, $namespace);
        } else {
            $source = $this->fallback->load($locale, $group, $namespace);
            $this->cache->put($locale, $group, $namespace, $source, $this->cacheTimeout);
            return $source;
        }
    }
1133272
public function createTranslations($e, $siteFolder, $locale)
    { 
    	$sm = $e->getApplication()->getServiceManager();
    	$translator = $sm->get('translator');
    	
    	$langFileTarget = $_SERVER['DOCUMENT_ROOT'] . '/../module/MelisSites/' .$siteFolder . '/language/' . $locale . '.php';
    	
    	if (!file_exists($langFileTarget))
    	{
    	    $langFileTarget = $_SERVER['DOCUMENT_ROOT'] . '/../module/MelisSites/' .$siteFolder . '/language/en_EN.php';
    	    
    	    if (!file_exists($langFileTarget))
    	    {
    	        $langFileTarget = null;
    	    }
    	}
    	else 
    	{
    	    $langFileTarget = null;
    	}
    	
    	if (!is_null($langFileTarget) && !empty($siteFolder) && !empty($locale))
    	{
    	    $translator->addTranslationFile(
    	        'phparray',
    	        $langFileTarget
	        );
    	}
    }
1014890
public function createCacheFile(string $hash, string $fileName, ?string $context = null): bool
    {
        foreach ($this->cacheAdapters as $cacheAdapter) {
            if ($cacheAdapter->create($hash, $fileName, $context)) {
                return true;
            }
        }

        return false;
    }
378862
private function withBuiltInTemplates(string $locale): ValidatorFactory
    {
        $templates = include(__DIR__ . '/../lang/' . $locale . '.php');

        return $this->withDefaultTemplates($templates);
    }
397823
public function getReaderForFile($filename, $mode, $use_include_path, $context)
    {
        $readers = $this->readers;
        if (!isset($readers[$filename])) {
            $reader = new BufferedFileRead();
            $result = $reader->fopen($filename, $mode, $use_include_path, $context);

            return $this->readers[$filename] = $result ? $reader : null;
        }
        return $readers[$filename];
    }