1616use Symfony \Component \Translation \MessageCatalogueInterface ;
1717use Symfony \Component \Translation \Reader \TranslationReader ;
1818use Symfony \Component \Translation \Writer \TranslationWriter ;
19+ use Symfony \Component \Translation \Writer \TranslationWriterInterface ;
1920use Translation \Common \Model \Message ;
2021use Translation \Common \Storage ;
2122use Translation \Common \TransferableStorage ;
2829final class FileStorage implements Storage, TransferableStorage
2930{
3031 /**
31- * @var TranslationWriter
32+ * @var TranslationWriterInterface|LegacyTranslationWriter
3233 */
3334 private $ writer ;
3435
@@ -60,6 +61,10 @@ final class FileStorage implements Storage, TransferableStorage
6061 */
6162 public function __construct (TranslationWriter $ writer , $ loader , array $ dir , array $ options = [])
6263 {
64+ // Create a legacy writer which is a wrapper for TranslationWriter
65+ if (!$ writer instanceof TranslationWriterInterface) {
66+ $ writer = new LegacyTranslationWriter ($ writer );
67+ }
6368 // Create a legacy loader which is a wrapper for TranslationReader
6469 if ($ loader instanceof TranslationReader) {
6570 $ loader = new LegacyTranslationLoader ($ loader );
@@ -164,7 +169,7 @@ private function writeCatalogue(MessageCatalogue $catalogue, $locale, $domain)
164169 $ path = (string ) $ resource ;
165170 if (preg_match ('|/ ' .$ domain .'\. ' .$ locale .'\.([a-z]+)$| ' , $ path , $ matches )) {
166171 $ options ['path ' ] = str_replace ($ matches [0 ], '' , $ path );
167- $ this ->writeTranslations ($ catalogue , $ matches [1 ], $ options );
172+ $ this ->writer -> write ($ catalogue , $ matches [1 ], $ options );
168173 $ written = true ;
169174 }
170175 }
@@ -176,7 +181,7 @@ private function writeCatalogue(MessageCatalogue $catalogue, $locale, $domain)
176181
177182 $ options ['path ' ] = reset ($ this ->dir );
178183 $ format = isset ($ options ['default_output_format ' ]) ? $ options ['default_output_format ' ] : 'xlf ' ;
179- $ this ->writeTranslations ($ catalogue , $ format , $ options );
184+ $ this ->writer -> write ($ catalogue , $ format , $ options );
180185 }
181186
182187 /**
@@ -210,23 +215,4 @@ private function loadCatalogue($locale, array $dirs)
210215
211216 $ this ->catalogues [$ locale ] = $ currentCatalogue ;
212217 }
213-
214- /**
215- * This method calls the new TranslationWriter::write() if exist,
216- * otherwise fallback to TranslationWriter::writeTranslations() call
217- * to avoid BC breaks.
218- *
219- * @param MessageCatalogue $catalogue
220- * @param string $format
221- * @param array $options
222- */
223- private function writeTranslations (MessageCatalogue $ catalogue , $ format , array $ options )
224- {
225- if (method_exists ($ this ->writer , 'write ' )) {
226- $ this ->writer ->write ($ catalogue , $ format , $ options );
227- } else {
228- // This method is deprecated since 3.4, maintained to avoid BC breaks
229- $ this ->writer ->writeTranslations ($ catalogue , $ format , $ options );
230- }
231- }
232218}
0 commit comments