Completed
Pull Request — master (#88)
by
unknown
64:04
created

XlfExport::export()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.2
cc 4
eloc 10
nc 5
nop 3
1
<?php
2
3
namespace ONGR\TranslationsBundle\Translation\Export;
4
5
use Symfony\Component\Translation\Dumper\XliffFileDumper;
6
use Symfony\Component\Translation\MessageCatalogue;
7
8
/**
9
 * Class XlfExport for dumping translations to yml file.
10
 */
11
class XlfExport implements ExporterInterface
12
{
13
    /**
14
     * Export translations in to the given file.
15
     *
16
     * @param string           $file
17
     * @param MessageCatalogue $translations
18
     * @param string           $domain
19
     *
20
     * @return bool
21
     */
22
    public function export($file, MessageCatalogue $translations, $domain)
23
    {
24
        if (pathinfo($file, PATHINFO_EXTENSION) === 'xlf') {
25
            $xlfDumper = new XliffFileDumper();
26
            try {
27
                $xlfContent = $xlfDumper->formatCatalogue($translations, $domain);
28
                if ($xlfContent !== false) {
29
                    return (file_put_contents($file, $xlfContent) !== false);
30
                }
31
            } catch (\Exception $e) {
32
                return false;
33
            }
34
        }
35
36
        return false;
37
    }
38
39
}