Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce602ce

Browse files
committed
[Translation] fixed docblock.
1 parent 54c1b66 commit ce602ce

File tree

3 files changed

+50
-54
lines changed

3 files changed

+50
-54
lines changed

src/Symfony/Component/Translation/CacheTranslatorBag.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\Config\ConfigCacheFactory;
1717

1818
/**
19+
* Manages cache catalogues.
20+
*
1921
* @author Abdellatif Ait boudad <[email protected]>
2022
*/
2123
class CacheTranslatorBag implements TranslatorBagInterface
@@ -26,7 +28,7 @@ class CacheTranslatorBag implements TranslatorBagInterface
2628
private $translatorBag;
2729

2830
/**
29-
* @var string|null
31+
* @var string
3032
*/
3133
private $cacheDir;
3234

@@ -36,15 +38,15 @@ class CacheTranslatorBag implements TranslatorBagInterface
3638
private $debug;
3739

3840
/**
39-
* @var ConfigCacheFactoryInterface|null
41+
* @var ConfigCacheFactoryInterface
4042
*/
4143
private $configCacheFactory;
4244

4345
/**
44-
* @param string|null $cacheDir The directory to use for the cache
45-
* @param bool $debug Use cache in debug mode ?
46-
* @param TranslatorBagInterface $translatorBag
47-
* @param ConfigCacheFactoryInterface $configCacheFactory
46+
* @param string $cacheDir The directory to use for the cache.
47+
* @param bool $debug Use cache in debug mode.
48+
* @param TranslatorBagInterface|null $translatorBag The translator bag to use for loading the catalogue.
49+
* @param ConfigCacheFactoryInterface|null $configCacheFactory The ConfigCache factory to use.
4850
*/
4951
public function __construct($cacheDir, $debug = false, TranslatorBagInterface $translatorBag = null, ConfigCacheFactoryInterface $configCacheFactory = null)
5052
{
@@ -70,16 +72,6 @@ function (ConfigCacheInterface $cache) use ($self, $locale) {
7072
return include $cache->getPath();
7173
}
7274

73-
/**
74-
* @internal
75-
*/
76-
public function initializeCatalogue($locale)
77-
{
78-
unlink($this->getCatalogueCachePath($locale));
79-
80-
return $this->getCatalogue($locale);
81-
}
82-
8375
/**
8476
* This method is public because it needs to be callable from a closure in PHP 5.3. It should be made protected (or even private, if possible) in 3.0.
8577
*

src/Symfony/Component/Translation/FallbackTranslatorBag.php

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,30 @@
1212
namespace Symfony\Component\Translation;
1313

1414
/**
15+
* Merges the fallback catalogues into the loaded one.
16+
*
1517
* @author Abdellatif Ait boudad <[email protected]>
1618
*/
1719
class FallbackTranslatorBag implements TranslatorBagInterface, TranslatorBagIdentifiable
1820
{
21+
/**
22+
* @var TranslatorBagInterface
23+
*/
1924
private $translatorBag;
2025

2126
/**
2227
* @var array
2328
*/
24-
private $fallbackLocales = array();
29+
private $fallbackLocales;
2530

31+
/**
32+
* @param array $fallbackLocales The fallback locales.
33+
* @param TranslatorBagInterface $translatorBag The translator bag to use for loading the catalogue.
34+
*/
2635
public function __construct($fallbackLocales = array(), TranslatorBagInterface $translatorBag = null)
2736
{
28-
$this->translatorBag = $translatorBag ?: new TranslatorBag();
2937
$this->fallbackLocales = $fallbackLocales;
38+
$this->translatorBag = $translatorBag ?: new TranslatorBag();
3039
}
3140

3241
/**
@@ -40,44 +49,10 @@ public function getCatalogue($locale)
4049
return $catalogue;
4150
}
4251

43-
private function loadFallbackCatalogues($catalogue, $locale)
44-
{
45-
$current = $catalogue;
46-
47-
foreach ($this->computeFallbackLocales($locale) as $fallback) {
48-
$catalogue = $this->translatorBag->getCatalogue($fallback);
49-
50-
$current->addFallbackCatalogue($catalogue);
51-
$current = $catalogue;
52-
}
53-
}
54-
55-
private function computeFallbackLocales($locale)
56-
{
57-
$locales = array();
58-
foreach ($this->fallbackLocales as $fallback) {
59-
if ($fallback === $locale) {
60-
continue;
61-
}
62-
63-
$locales[] = $fallback;
64-
}
65-
66-
if (strrchr($locale, '_') !== false) {
67-
array_unshift($locales, substr($locale, 0, -strlen(strrchr($locale, '_'))));
68-
}
69-
70-
return array_unique($locales);
71-
}
72-
7352
/**
7453
* Sets the fallback locales.
7554
*
7655
* @param array $locales The fallback locales
77-
*
78-
* @throws \InvalidArgumentException If a locale contains invalid characters
79-
*
80-
* @api
8156
*/
8257
public function setFallbackLocales(array $locales)
8358
{
@@ -88,8 +63,6 @@ public function setFallbackLocales(array $locales)
8863
* Gets the fallback locales.
8964
*
9065
* @return array $locales The fallback locales
91-
*
92-
* @api
9366
*/
9467
public function getFallbackLocales()
9568
{
@@ -108,4 +81,33 @@ public function getIdentifier()
10881

10982
return sha1($id);
11083
}
84+
85+
private function loadFallbackCatalogues($catalogue, $locale)
86+
{
87+
$current = $catalogue;
88+
foreach ($this->computeFallbackLocales($locale) as $fallback) {
89+
$catalogue = $this->translatorBag->getCatalogue($fallback);
90+
91+
$current->addFallbackCatalogue($catalogue);
92+
$current = $catalogue;
93+
}
94+
}
95+
96+
private function computeFallbackLocales($locale)
97+
{
98+
$locales = array();
99+
foreach ($this->fallbackLocales as $fallback) {
100+
if ($fallback === $locale) {
101+
continue;
102+
}
103+
104+
$locales[] = $fallback;
105+
}
106+
107+
if (strrchr($locale, '_') !== false) {
108+
array_unshift($locales, substr($locale, 0, -strlen(strrchr($locale, '_'))));
109+
}
110+
111+
return array_unique($locales);
112+
}
111113
}

src/Symfony/Component/Translation/TranslatorBag.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Translation\Loader\LoaderInterface;
1515

1616
/**
17+
* TranslatorBag loads catalogue from resources.
18+
*
1719
* @author Abdellatif Ait boudad <[email protected]>
1820
*/
1921
class TranslatorBag implements TranslatorBagInterface, TranslatorBagIdentifiable

0 commit comments

Comments
 (0)