File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
4
4
5
+ ## 0.3.1
6
+
7
+ ### Fixed
8
+
9
+ - Make sure XliffLoader can load from resource
10
+
5
11
## 0.3.0
6
12
7
13
### Added
Original file line number Diff line number Diff line change 12
12
namespace Translation \SymfonyStorage \Loader ;
13
13
14
14
use Nyholm \NSA ;
15
+ use Symfony \Component \Config \Resource \FileResource ;
16
+ use Symfony \Component \Translation \Exception \NotFoundResourceException ;
15
17
use Symfony \Component \Translation \Loader \XliffFileLoader ;
16
18
use Symfony \Component \Translation \MessageCatalogue ;
17
19
use Symfony \Component \Translation \Exception \InvalidResourceException ;
@@ -29,6 +31,30 @@ class XliffLoader extends XliffFileLoader
29
31
*/
30
32
private $ sfPort ;
31
33
34
+ /**
35
+ * {@inheritdoc}
36
+ */
37
+ public function load ($ resource , $ locale , $ domain = 'messages ' )
38
+ {
39
+ if (!stream_is_local ($ resource )) {
40
+ throw new InvalidResourceException (sprintf ('This is not a local file "%s". ' , $ resource ));
41
+ }
42
+
43
+ if (!file_exists ($ resource )) {
44
+ throw new NotFoundResourceException (sprintf ('File "%s" not found. ' , $ resource ));
45
+ }
46
+
47
+ $ catalogue = new MessageCatalogue ($ locale );
48
+ $ content = file_get_contents ($ resource );
49
+ $ this ->extractFromContent ($ content , $ catalogue , $ domain );
50
+
51
+ if (class_exists ('Symfony\Component\Config\Resource\FileResource ' )) {
52
+ $ catalogue ->addResource (new FileResource ($ resource ));
53
+ }
54
+
55
+ return $ catalogue ;
56
+ }
57
+
32
58
/**
33
59
* @param string $content xml content
34
60
* @param MessageCatalogue $catalogue
Original file line number Diff line number Diff line change @@ -105,4 +105,25 @@ public function testXliff20Meta()
105
105
$ this ->assertEquals ('1 ' , $ metadata ['notes ' ][2 ]['priority ' ]);
106
106
$ this ->assertEquals ('user login ' , $ metadata ['notes ' ][2 ]['content ' ]);
107
107
}
108
+
109
+ public function testXliff20FromResource ()
110
+ {
111
+ $ file = __DIR__ .'/../../Fixtures/meta.en.xlf ' ;
112
+
113
+ $ catalogue = (new XliffLoader ())->load ($ file , 'en ' , 'messages ' );
114
+ $ this ->assertTrue ($ catalogue ->defines ('foo ' ));
115
+ $ metadata = $ catalogue ->getMetadata ('foo ' );
116
+ $ this ->assertNotEmpty ($ metadata );
117
+ $ this ->assertCount (3 , $ metadata ['notes ' ]);
118
+
119
+ $ this ->assertEquals ('state ' , $ metadata ['notes ' ][0 ]['category ' ]);
120
+ $ this ->assertEquals ('new ' , $ metadata ['notes ' ][0 ]['content ' ]);
121
+
122
+ $ this ->assertEquals ('approved ' , $ metadata ['notes ' ][1 ]['category ' ]);
123
+ $ this ->assertEquals ('true ' , $ metadata ['notes ' ][1 ]['content ' ]);
124
+
125
+ $ this ->assertEquals ('section ' , $ metadata ['notes ' ][2 ]['category ' ]);
126
+ $ this ->assertEquals ('1 ' , $ metadata ['notes ' ][2 ]['priority ' ]);
127
+ $ this ->assertEquals ('user login ' , $ metadata ['notes ' ][2 ]['content ' ]);
128
+ }
108
129
}
You can’t perform that action at this time.
0 commit comments