Skip to content

Commit 5206603

Browse files
committed
minor symfony#14316 [Translation] improved exception when missing required component (xabbuh)
This PR was merged into the 2.3 branch. Discussion ---------- [Translation] improved exception when missing required component | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#13194 | License | MIT | Doc PR | Commits ------- c3bd418 improved exception when missing required component
2 parents db24362 + c3bd418 commit 5206603

File tree

11 files changed

+48
-10
lines changed

11 files changed

+48
-10
lines changed

src/Symfony/Component/Translation/Dumper/YamlFileDumper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ class YamlFileDumper extends FileDumper
2626
*/
2727
protected function format(MessageCatalogue $messages, $domain)
2828
{
29+
if (!class_exists('Symfony\Component\Yaml\Yaml')) {
30+
throw new \LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
31+
}
32+
2933
return Yaml::dump($messages->all($domain));
3034
}
3135

src/Symfony/Component/Translation/Loader/CsvFileLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ public function load($resource, $locale, $domain = 'messages')
7171
}
7272

7373
$catalogue = parent::load($messages, $locale, $domain);
74-
$catalogue->addResource(new FileResource($resource));
74+
75+
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
76+
$catalogue->addResource(new FileResource($resource));
77+
}
7578

7679
return $catalogue;
7780
}

src/Symfony/Component/Translation/Loader/IcuDatFileLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public function load($resource, $locale, $domain = 'messages')
5252
$messages = $this->flatten($rb);
5353
$catalogue = new MessageCatalogue($locale);
5454
$catalogue->add($messages, $domain);
55-
$catalogue->addResource(new FileResource($resource.'.dat'));
55+
56+
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
57+
$catalogue->addResource(new FileResource($resource.'.dat'));
58+
}
5659

5760
return $catalogue;
5861
}

src/Symfony/Component/Translation/Loader/IcuResFileLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public function load($resource, $locale, $domain = 'messages')
5252
$messages = $this->flatten($rb);
5353
$catalogue = new MessageCatalogue($locale);
5454
$catalogue->add($messages, $domain);
55-
$catalogue->addResource(new DirectoryResource($resource));
55+
56+
if (class_exists('Symfony\Component\Config\Resource\DirectoryResource')) {
57+
$catalogue->addResource(new DirectoryResource($resource));
58+
}
5659

5760
return $catalogue;
5861
}

src/Symfony/Component/Translation/Loader/IniFileLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ public function load($resource, $locale, $domain = 'messages')
3838
$messages = parse_ini_file($resource, true);
3939

4040
$catalogue = parent::load($messages, $locale, $domain);
41-
$catalogue->addResource(new FileResource($resource));
41+
42+
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
43+
$catalogue->addResource(new FileResource($resource));
44+
}
4245

4346
return $catalogue;
4447
}

src/Symfony/Component/Translation/Loader/MoFileLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ public function load($resource, $locale, $domain = 'messages')
6666
}
6767

6868
$catalogue = parent::load($messages, $locale, $domain);
69-
$catalogue->addResource(new FileResource($resource));
69+
70+
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
71+
$catalogue->addResource(new FileResource($resource));
72+
}
7073

7174
return $catalogue;
7275
}

src/Symfony/Component/Translation/Loader/PhpFileLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ public function load($resource, $locale, $domain = 'messages')
4242
$messages = require $resource;
4343

4444
$catalogue = parent::load($messages, $locale, $domain);
45-
$catalogue->addResource(new FileResource($resource));
45+
46+
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
47+
$catalogue->addResource(new FileResource($resource));
48+
}
4649

4750
return $catalogue;
4851
}

src/Symfony/Component/Translation/Loader/PoFileLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ public function load($resource, $locale, $domain = 'messages')
4444
}
4545

4646
$catalogue = parent::load($messages, $locale, $domain);
47-
$catalogue->addResource(new FileResource($resource));
47+
48+
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
49+
$catalogue->addResource(new FileResource($resource));
50+
}
4851

4952
return $catalogue;
5053
}

src/Symfony/Component/Translation/Loader/QtFileLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ public function load($resource, $locale, $domain = 'messages')
6868
}
6969
$translation = $translation->nextSibling;
7070
}
71-
$catalogue->addResource(new FileResource($resource));
71+
72+
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
73+
$catalogue->addResource(new FileResource($resource));
74+
}
7275
}
7376

7477
libxml_use_internal_errors($internalErrors);

src/Symfony/Component/Translation/Loader/XliffFileLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public function load($resource, $locale, $domain = 'messages')
6969

7070
$catalogue->set((string) $source, $target, $domain);
7171
}
72-
$catalogue->addResource(new FileResource($resource));
72+
73+
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
74+
$catalogue->addResource(new FileResource($resource));
75+
}
7376

7477
return $catalogue;
7578
}

0 commit comments

Comments
 (0)