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

XliffConverter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 37.5%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A contentToCatalogue() 0 8 1
A catalogueToContent() 0 6 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