@@ -34,6 +34,7 @@ class XliffDumper implements DumperInterface
3434{
3535 private $ sourceLanguage = 'en ' ;
3636 private $ addDate = true ;
37+ private $ addSources = true ;
3738
3839 /**
3940 * @param $bool
@@ -43,6 +44,14 @@ public function setAddDate($bool)
4344 $ this ->addDate = (Boolean ) $ bool ;
4445 }
4546
47+ /**
48+ * @param boolean $addSources
49+ */
50+ public function setAddSources ($ addSources )
51+ {
52+ $ this ->addSources = $ addSources ;
53+ }
54+
4655 /**
4756 * @param $lang
4857 */
@@ -115,24 +124,27 @@ public function dump(MessageCatalogue $catalogue, $domain = 'messages')
115124 $ target ->setAttribute ('state ' , 'new ' );
116125 }
117126
118- // As per the OASIS XLIFF 1.2 non-XLIFF elements must be at the end of the <trans-unit>
119- if ($ sources = $ message ->getSources ()) {
120- foreach ($ sources as $ source ) {
121- if ($ source instanceof FileSource) {
122- $ unit ->appendChild ($ refFile = $ doc ->createElement ('jms:reference-file ' , $ source ->getPath ()));
127+ if ($ this ->addSources ) {
128+ // As per the OASIS XLIFF 1.2 non-XLIFF elements must be at the end of the <trans-unit>
129+ if ($ sources = $ message ->getSources ()) {
130+ foreach ($ sources as $ source ) {
131+ if ($ source instanceof FileSource) {
132+ $ refFile = $ doc ->createElement ('jms:reference-file ' , $ source ->getPath ());
133+ $ unit ->appendChild ($ refFile );
123134
124- if ($ source ->getLine ()) {
125- $ refFile ->setAttribute ('line ' , $ source ->getLine ());
126- }
135+ if ($ source ->getLine ()) {
136+ $ refFile ->setAttribute ('line ' , $ source ->getLine ());
137+ }
127138
128- if ($ source ->getColumn ()) {
129- $ refFile ->setAttribute ('column ' , $ source ->getColumn ());
139+ if ($ source ->getColumn ()) {
140+ $ refFile ->setAttribute ('column ' , $ source ->getColumn ());
141+ }
142+
143+ continue ;
130144 }
131145
132- continue ;
146+ $ unit -> appendChild ( $ doc -> createElementNS ( ' jms:reference ' , ( string ) $ source )) ;
133147 }
134-
135- $ unit ->appendChild ($ doc ->createElementNS ('jms:reference ' , (string ) $ source ));
136148 }
137149 }
138150
@@ -144,4 +156,4 @@ public function dump(MessageCatalogue $catalogue, $domain = 'messages')
144156
145157 return $ doc ->saveXML ();
146158 }
147- }
159+ }
0 commit comments