Completed
Push — master ( e4a30a...1a3d0b )
by Tobias
07:42
created

XliffConverter::catalogueToContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\SymfonyStorage;
13
14
use Symfony\Component\Translation\MessageCatalogue;
15
use Translation\SymfonyStorage\Dumper\XliffDumper;
16
use Translation\SymfonyStorage\Loader\XliffLoader;
17
18
/**
19
 * Utility class to convert between a MessageCatalogue and XLIFF file content.
20
 *
21
 * @author Tobias Nyholm <[email protected]>
22
 */
23
final class XliffConverter
24
{
25
    /**
26
     * Create a catalogue from the contents of a XLIFF file.
27
     *
28
     * @param string $content
29
     * @param string $locale
30
     * @param string $domain
31
     *
32
     * @return MessageCatalogue
33
     */
34
    public static function contentToCatalogue($content, $locale, $domain)
35
    {
36
        $loader = new XliffLoader();
37
        $catalogue = new MessageCatalogue($locale);
38
        $loader->extractFromContent($content, $catalogue, $domain);
39
40
        return $catalogue;
41
    }
42
43
    /**
44
     * @param MessageCatalogue $catalogue
45
     * @param string           $domain
46
     *
47
     * @return string
48
     */
49 1
    public static function catalogueToContent(MessageCatalogue $catalogue, $domain)
50
    {
51 1
        $dumper = new XliffDumper();
52
53 1
        return $dumper->getFormattedCatalogue($catalogue, $domain);
54
    }
55
}
56