/**
* Loads a locale.
*
* @param mixed $resource A resource
* @param string $locale A locale
* @param string $domain The domain
*
* @return MessageCatalogue A MessageCatalogue instance
*
* @throws NotFoundResourceException when the resource cannot be found
* @throws InvalidResourceException when the resource cannot be loaded
*/
public function load($resource, $locale, $domain = 'messages')
{
if ($this->loadAll !== true) {
return new MessageCatalogue($locale);
}
$dql = <<<'DQL'
SELECT
t
FROM
MjrLibraryEntitiesBundle:System\Translation t
WHERE
t.Locale = :locale
ORDER BY t.Id ASC
DQL;
$query = $this->entityManager->createQuery($dql);
$query->setParameter(':locale', $locale);
/** @var Translation[] $results */
$results = $query->getResult();
$catalogue = new MessageCatalogue($locale);
if (count($results) > 0) {
foreach ($results as $result) {
$catalogue->set($result->getIdentity(), $result->getTranslation(), $domain);
}
}
return $catalogue;
}