Completed
Push — master ( 659b14...17b09c )
by Tobias
07:00
created

XliffConverter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A catalogueToContent() 0 6 1
A contentToCatalogue() 0 8 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 1
    public static function contentToCatalogue($content, $locale, $domain)
35
    {
36 1
        $loader = new XliffLoader();
37 1
        $catalogue = new MessageCatalogue($locale);
38 1
        $loader->extractFromContent($content, $catalogue, $domain);
39
40 1
        return $catalogue;
41
    }
42
43
    /**
44
     * @param MessageCatalogue $catalogue
45
     * @param string           $domain
46
     * @param array            $options
47
     *
48
     * @return string
49
     */
50 1
    public static function catalogueToContent(MessageCatalogue $catalogue, $domain, array $options = [])
51
    {
52 1
        $dumper = new XliffDumper();
53
54 1
        return $dumper->getFormattedCatalogue($catalogue, $domain, $options);
55
    }
56
}
57