Completed
Push — master ( 1397e0...6a2cd6 )
by Sascha-Oliver
9s
created

XliffConverter::catalogueToContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 3
crap 2
1
<?php
2
3
namespace Translation\PlatformAdapter\PhraseApp\Bridge\Symfony;
4
5
use Symfony\Component\Translation\MessageCatalogue;
6
use Translation\SymfonyStorage\Dumper\XliffDumper;
7
use Translation\SymfonyStorage\Loader\XliffLoader;
8
9
/**
10
 * Utility class to convert between a MessageCatalogue and XLIFF file content.
11
 *
12
 * This class can be removed when https://github.com/php-translation/symfony-storage/pull/8 is accepted and merged
13
 */
14
final class XliffConverter
15
{
16
    /**
17
     * Create a catalogue from the contents of a XLIFF file.
18
     *
19
     * @param string $content
20
     * @param string $locale
21
     * @param string $domain
22
     *
23
     * @return MessageCatalogue
24
     */
25
    public static function contentToCatalogue($content, $locale, $domain)
26
    {
27
        $loader = new XliffLoader();
28
        $catalogue = new MessageCatalogue($locale);
29
        $loader->extractFromContent($content, $catalogue, $domain);
30
31
        return $catalogue;
32
    }
33
34
    /**
35
     * @param MessageCatalogue $catalogue
36
     * @param string           $domain
37
     * @param array            $options
38
     *
39
     * @return string
40
     */
41
    public static function catalogueToContent(MessageCatalogue $catalogue, $domain, array $options = [])
42
    {
43
        $dumper = new XliffDumper();
44
45
        return $dumper->getFormattedCatalogue($catalogue, $domain, $options);
46
    }
47
}
48