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 22
33The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44
5+ ## 0.3.1
6+
7+ ### Fixed
8+
9+ - Make sure XliffLoader can load from resource
10+
511## 0.3.0
612
713### Added
Original file line number Diff line number Diff line change 1212namespace Translation \SymfonyStorage \Loader ;
1313
1414use Nyholm \NSA ;
15+ use Symfony \Component \Config \Resource \FileResource ;
16+ use Symfony \Component \Translation \Exception \NotFoundResourceException ;
1517use Symfony \Component \Translation \Loader \XliffFileLoader ;
1618use Symfony \Component \Translation \MessageCatalogue ;
1719use Symfony \Component \Translation \Exception \InvalidResourceException ;
@@ -29,6 +31,30 @@ class XliffLoader extends XliffFileLoader
2931 */
3032 private $ sfPort ;
3133
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+
3258 /**
3359 * @param string $content xml content
3460 * @param MessageCatalogue $catalogue
Original file line number Diff line number Diff line change @@ -105,4 +105,25 @@ public function testXliff20Meta()
105105 $ this ->assertEquals ('1 ' , $ metadata ['notes ' ][2 ]['priority ' ]);
106106 $ this ->assertEquals ('user login ' , $ metadata ['notes ' ][2 ]['content ' ]);
107107 }
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+ }
108129}
You can’t perform that action at this time.
0 commit comments