Initialize the catalog for the exact locale and exact domain

@param  string $locale
@param  string $domain
@throws InvalidParameter
965023
protected function initCatalogsForSingleLocale($locale, $domain) {
		if (is_string($domain)) {
			$this->initCatalog($locale, $domain);
			return;
		}
			
		if (is_array($domain)) {
			$this->initCatalogForManyDomains($locale, $domain);
			return;
		}
		
		throw new InvalidParameter('Domain must be a string or an array');
	}
135937
private function buildPath($domain, $locale)
    {
        $path = '/resources/translations/' . $locale . '/' . $domain . '.' . $locale . '.yml';

        // If long locale dir doesn't exists try short locale and return it if that exists
        if (strlen($locale) == 5 && !is_dir($this->app['path_resolver']->resolve('%root%/app' . $path))) {
            $paths = $this->buildPath($domain, substr($locale, 0, 2));

            if (is_dir($paths[0])) {
                return $paths;
            }
        }

        return [
            $this->app['path_resolver']->resolve('%root%/app' . $path),
            'app' . $path,
        ];
    }
792218
protected function getValue($string, $domain, $locale)
    {
        if (!$domain) {
            $domain = 'default';
        }

        if (!$locale) {
            $locale = 'default';
        }

        if (!isset($this->values[$locale][$domain][$string])) {
            return $string;
        }

        return $this->values[$locale][$domain][$string];
    }
361659
public function load($resource, $locale, $domain = 'messages')
    {
        /* @var MessageCatalogue $catalogue */
        $base_catalogue = parent::load($resource, $locale, $domain);
        $catalogue = new MessageCatalogue($locale);
        $catalogue->addCatalogue($base_catalogue);

        // Process a second pass over the file to collect metadata
        $xml = simplexml_load_file($resource);
        $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
        foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
            // Read the attributes
            $attributes = (array) $translation->attributes();
            $attributes = $attributes['@attributes'];
            if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) {
                continue;
            }
            $key = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
            $metadata = (array) $attributes;

            // read the notes
            if (isset($translation->note)) {
                $metadata['note'] = (string) $translation->note;
            }

            $catalogue->setMetadata((string) $key, $metadata, $domain);
        }

        return $catalogue;
    }
892812
protected function initCatalog($locale, $domain) {
		if (isset($this->initializedCatalogs[$locale][$domain])) {
			return;
		}
		
		switch ($this->sectionsMode) {
			case self::SECTIONS_IGNORE:
				$this->initExact($locale, $domain);
				break;
			
			case self::SECTIONS_DOMAIN:
				$this->initManyDomains($locale, $domain);
				break;
			
			case self::SECTIONS_LOCALE:
				$this->initManyLocales($locale, $domain);
				break;
		}
		
		if (! isset($this->initializedCatalogs[$locale])) {
			$this->initializedCatalogs[$locale] = [];
		}

		$this->initializedCatalogs[$locale][$domain] = true;
	}
1047311
public function setLocale($locale)
    {
        if (null !== $locale && !array_key_exists($locale, Application::getAvailableLanguages())) {
            throw new InvalidArgumentException(sprintf('Invalid locale %s.', $locale));
        }

        $this->locale = $locale;

        return $this;
    }
467334
public function setLocale($locale) {
		$this->locale          = trim($locale);
		$this->primaryLanguage = IntlLocale::getPrimaryLanguage($this->locale);
	}
848863
protected function handlePreinit($locale, $domain) {
		if (! empty($this->preinitLocales)) {
			$locale = array_unique(array_merge(
				(array) $locale, 
				$this->preinitLocales
			));
		}

		if (! empty($this->preinitDomains)) {
			$domain = array_unique(array_merge(
				(array) $domain,
				$this->preinitDomains
			));
		}
		
		$this->preinitNeed = false;
		
		return [$locale, $domain];
	}
4402
public function translator(string $locale, string $domain, string $directory): ?TranslatorInterface
    {
        $class = GETTEXT_EXTENSION ? GettextTranslator::class : Translator::class;

        $previous = self::$translator;
        self::$translator = new $class($locale, $domain, $directory);

        if ($previous === null) {
            require __DIR__ . DIRECTORY_SEPARATOR . 'helpers.php';
        }

        $this->locale = $locale;

        return $previous;
    }
1073188
private function setLocale(string $locale)
    {
        $arr = \Locale::parseLocale($locale);
        
        if ($arr === false) {
            throw new \InvalidArgumentException('Invalid locale');
        }
        
        $this->locale = $arr;
    }
427528
public function getAllByLocaleAndDomain($locale, $domain)
    {
        return $this->createQueryBuilder('tu')
            ->select('tu, te')
            ->leftJoin('tu.translations', 'te')
            ->where('tu.domain = :domain')
            ->andWhere('te.locale = :locale')
            ->setParameter('domain', $domain)
            ->setParameter('locale', $locale)
            ->getQuery()
            ->getArrayResult();
    }
854210
public function setDomain(Domain $domain)
    {
        $this->domain = $domain;
        $this->domainId = $domain->getDomainId();
    }
559332
public function load($resource, $locale, $domain = 'messages')
    {
        $catalogue = new MessageCatalogue($locale);

        foreach ($this->repository->getTranslations($locale, $domain) as $id => $translation) {
            $catalogue->set($id, $translation, $domain);
        }

        return $catalogue;
    }
1235323
protected function getCatalogContent($locale, $domain) {
		$path = $this->getCatalogPath($locale, $domain);
		
		if (! is_file($path)) {
			return false;
		}
		
		if (! is_readable($path)) {
			throw new ReadError('Catalog file: "' . $path . '" exists but can\'t be read');
		}
		
		$result = file_get_contents($path);
		
		if ($result === false) {
			throw new ReadError('Error has occurred while reading the file: "' . $path . '"');
		}
		
		$this->lastFilePath = $path;
		
		return $result;
	}
690956
public function setLocale($locale)
    {
        $result = true;

        // Check if locale is valid
        if (!$this->isValidLocale($locale)) {
            throw new Doozr_I18n_Service_Exception(
                sprintf('The locale "%s" is not valid.', $locale)
            );
        }

        $this->locale = $locale;

        return $result;
    }
286705
public function setLocale($locale)
    {
        if (!$this->catalogueManager->has($locale)) {
            throw new LocaleException($locale);
        }

        $this->locale = $locale;
        $this->catalogueManager->load($locale);

        return $this;
    }
1164518
private function buildContent($locale, $domain)
    {
        $translations = [];
        $resources = [];

        if ($locale !== $this->fallbackLocale) {
            $fallbackCatalogue = $this->translator->getCatalogue($this->fallbackLocale);
            $resources = array_merge($resources, $fallbackCatalogue->getResources());
            $translations = array_merge($translations, $this->extractor->extract($fallbackCatalogue, $domain));
        }

        $catalogue = $this->translator->getCatalogue($locale);
        $resources = array_merge($resources, $catalogue->getResources());
        $translations = array_merge($translations, $this->extractor->extract($catalogue, $domain));

        $content = $this->builder->build($translations, $locale);

        return new ResourceContent($content, $resources);
    }