Create a xliff instance for the passed resource.

@param TranslationResource $resource     The resource.

@param string              $languageCode The language code.

@return XliffFile
165662
private function getLocalXliffFile(TranslationResource $resource, $languageCode)
    {
        $domain    = substr($resource->getSlug(), strlen($this->prefix));
        $localFile = $this->txlang . DIRECTORY_SEPARATOR .
            substr($languageCode, 0, 2) . DIRECTORY_SEPARATOR .
            $domain . '.xlf';

        $local = new XliffFile($localFile);
        if (!file_exists($localFile)) {
            // Set base values.
            $local->setDataType('php');
            $local->setOriginal($domain);
            $local->setSrcLang($this->baselanguage);
            $local->setTgtLang(substr($languageCode, 0, 2));
        }

        return $local;
    }
197466
public function getOne($languageCode, $locale = 'en')
	{

		$result = $this->has($languageCode, $locale);

		if (!$result)
		{
			throw new LanguageNotFoundException($languageCode);
		}

		return $result;
	}
640747
public function removeExistingTranslation($languageCode)
    {
        return $this->translations()
            ->where('file_id', $this->id)
            ->where('language_code', $languageCode)
            ->delete();
    }
583676
public static function localeName($code, $in_code = null)
    {
        $code = str_replace('-', '_', $code);
        $in_code = str_replace('-', '_', $in_code ?: \Locale::getDefault());

        static $languages;
        if (!isset($languages[$in_code])) {
            $languages[$in_code] = [];
            $resource = \ResourceBundle::create($in_code, 'ICUDATA-lang')->get('Languages');
            foreach($resource as $name => $value) {
                $languages[$in_code][$name] = $value;
            }
        }

        return isset($languages[$in_code][$code])
            ? $languages[$in_code][$code]
            : \Locale::getDisplayName($code, $in_code);
    }
135510
public function beginExport(TranslatableInterface $translatable, $targetLang) {

    $this->openMemory();
    $this->setIndent(TRUE);
    $this->setIndentString(' ');
    $this->startDocument('1.0', 'UTF-8');

    // Root element with schema definition.
    $this->startElement('xliff');
    $this->writeAttribute('version', '1.2');
    $this->writeAttribute('xmlns:xlf', 'urn:oasis:names:tc:xliff:document:1.2');
    $this->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
    $this->writeAttribute('xmlns:html', 'http://www.w3.org/1999/xhtml');
    $this->writeAttribute('xsi:schemaLocation', 'urn:oasis:names:tc:xliff:document:1.2 xliff-core-1.2-strict.xsd');

    // File element.
    $this->startElement('file');
    $this->writeAttribute('original', 'xliff-core-1.2-strict.xsd');
    $this->writeAttribute('source-language', $this->sourceLang);
    $this->writeAttribute('target-language', $targetLang);
    $this->writeAttribute('datatype', 'plaintext');

    // Date needs to be in ISO-8601 UTC.
    $this->writeAttribute('date', date('Y-m-d\Th:m:i\Z'));

    $this->startElement('header');
    $this->startElement('phase-group');
    $this->startElement('phase');
    $this->writeAttribute('tool-id', 'eggs-n-cereal');
    $this->writeAttribute('phase-name', 'extraction');
    $this->writeAttribute('process-name', 'extraction');
    $this->writeAttribute('job-id', $translatable->getIdentifier());

    $this->endElement();
    $this->endElement();
    $this->startElement('tool');
    $this->writeAttribute('tool-id', 'eggs-n-cereal');
    $this->writeAttribute('tool-name', 'Eggs-n-Cereal XLIFF Serializer');
    $this->endElement();
    $this->endElement();

    return $this->outputMemory() . '<body>';
  }
73390
public function setLanguage($code = null)
    {
        if (!isset($code)) {
            $code = $this->config->get('cli_langcode', '');
        }

        $this->langcode = $code;
        $this->translation->set($code, null);

        return $this;
    }
831847
public function loadJsTranslation($langcode = null)
    {
        $strings = $this->loadTranslation($this->getContextJsFile($langcode));

        $translations = array();
        foreach ($strings as $source => $translation) {
            if (isset($translation[0]) && $translation[0] !== '') {
                $translations[$source] = $translation;
            }
        }

        return $translations;
    }
1067402
public function getActiveTranslation($languageCode)
    {
        return $this->translations->first(function ($translation) use ($languageCode) {
            return $translation->is_active === true && $translation->language_code === $languageCode;
        });
    }
1093817
public function loadByLanguageCode($languageCode)
    {
        $language = $this->cache->get('ez-language-code-' . $languageCode);
        if ($language === null) {
            $language = $this->innerHandler->loadByLanguageCode($languageCode);
            $this->storeCache([$language]);
        }

        return $language;
    }
869269
public static function getLangResourceByCode($code)
    {
        $langs = self::getAvailableLangs();
        return isset($langs[$code]) ? new core_kernel_classes_Resource($langs[$code]['uri']) : null; 
    }
14505
public static function contentToCatalogue($content, $locale, $domain)
    {
        $loader = new XliffLoader();
        $catalogue = new MessageCatalogue($locale);
        $loader->extractFromContent($content, $catalogue, $domain);

        return $catalogue;
    }
1086649
public function add(string $key): WritableTranslationValueInterface
    {
        if ($this->xliff->searchTranslationUnit($key)) {
            throw new TranslationAlreadyContainedException($key, $this);
        }

        $this->markChanged();

        return new WritableXliffTranslationValue($this, $this->xliff->createTranslationUnit($key));
    }
526229
public function getLanguage($languageCode = null): ?string
    {
        $languageCode = $languageCode ? mb_strtoupper($languageCode) : null;

        return $this->get("languages.{$languageCode}") ?: (current($this->get('languages', [])) ?: null);
    }
979699
public function createTranslator($locale, $class = null, $cacheDir = null, $debug = false)
    {
        if (null === $class) {
            $class = '\Symfony\Component\Translation\Translator';
        }
        if (null === $locale) {
            $locale = 'en';
        }
        /** @var Translator $translator */
        $translator = new $class($locale, null, $cacheDir, $debug);
        $translator->addLoader('xml', new XliffFileLoader());
        $configuration = new SanityCheckConfiguration();
        $translations = $configuration->getTranslationResources();
        foreach ($translations as $locale => $resources) {
            foreach ($resources as $resource) {
                $translator->addResource('xml', $resource, $locale, 'chameleon_system_sanitycheck');
            }
        }

        return $translator;
    }
969436
public static function mapCode2InterfaceLanguage($code)
    {
        if (!empty($code)) {
            $languageService = tao_models_classes_LanguageService::singleton();
            $usage = new core_kernel_classes_Resource(tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_GUI);
            if ($languageService->isLanguageAvailable($code, $usage)) {
                return $code;
            }
            \common_Logger::d('[Fallback] The provided launch language is unavailable: ' . $code);
        }

        return DEFAULT_LANG;
    }
199586
public static function languageCountryLocaleCode($languageCode, $countryCode)
    {
        $countryLocaleCodes = static::countryLocaleCodes($countryCode);
        $languageLocaleCodes = static::languageLocaleCodes($languageCode);
        if ($localeCodes = array_intersect($languageLocaleCodes, $countryLocaleCodes)) {
            return reset($localeCodes);
        }

        return \Locale::composeLocale([
            'language' => $languageCode,
            'region' => $countryCode,
        ]);
    }
966443
public function isTargetLanguageVersionExist(string $languageCode): bool
    {
        $languages = $this->repository->getContentLanguageService()->loadLanguages();
        foreach ($languages as $language) {
            if ($language->enabled && $language->languageCode == $languageCode) {
                return true;
            }
        }

        return false;
    }