Skip to content

Commit 35c1e58

Browse files
author
Wim Vandersmissen
committed
Merge pull request #43 from Kunstmaan/translator-bugfix
Bugfix for Translator
2 parents 6a64041 + 992c0c1 commit 35c1e58

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

Service/Translator/Translator.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public function addResourcesFromCacher()
5050

5151
/**
5252
* Add resources from the stash and cache them
53+
*
5354
* @param boolean $cacheResources cache resources after retrieving them from the stasher
5455
*/
5556
public function addResourcesFromDatabaseAndCacheThem($cacheResources = true)
@@ -67,13 +68,14 @@ public function addResourcesFromDatabaseAndCacheThem($cacheResources = true)
6768
* Add resources to the Translator
6869
* Resources is an array[0] => array('name' => 'messages', 'locale' => 'en')
6970
* Where name is the domain of the domain
71+
*
7072
* @param array $resources
7173
*/
7274
public function addResources($resources)
7375
{
7476
foreach ($resources as $resource) {
7577
$this->addResource('database', 'DB', $resource['locale'], $resource['name']);
76-
}
78+
}
7779
}
7880

7981
/**
@@ -91,13 +93,15 @@ protected function loadCatalogue($locale)
9193

9294
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null)
9395
{
96+
if (!$this->container->isScopeActive('request')) {
97+
return parent::trans($id, $parameters, $domain, $locale);
98+
}
9499

95100
$showTranslationsSource = $this->container->get('request')->get('transSource');
96-
if($showTranslationsSource !== null) {
97-
$trans = sprintf('%s (%s)', $id, $domain);
101+
if ($showTranslationsSource !== null) {
102+
$trans = sprintf('%s (%s)', $id, $domain);
98103
} else {
99104
$trans = parent::trans($id, $parameters, $domain, $locale);
100-
101105
}
102106

103107
$this->profileTranslation($id, $parameters, $domain, $locale, $trans);
@@ -128,7 +132,7 @@ public function profileTranslation($id, $parameters, $domain, $locale, $trans)
128132
$translationCollection = new ArrayCollection;
129133
}
130134

131-
$translationCollection->set($domain.$id.$locale, $translation);
135+
$translationCollection->set($domain . $id . $locale, $translation);
132136

133137
$this->container->get('request')->request->set('usedTranslations', $translationCollection);
134138

0 commit comments

Comments
 (0)