I18n   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 16
dl 0
loc 60
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 23 5
1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package laravel
7
 * @subpackage Base
8
 */
9
10
namespace Aimeos\Shop\Base;
11
12
13
/**
14
 * Service providing the internationalization objects
15
 *
16
 * @package laravel
17
 * @subpackage Base
18
 */
19
class I18n
20
{
21
	/**
22
	 * @var \Aimeos\Shop\Base\Aimeos
23
	 */
24
	private $aimeos;
25
26
	/**
27
	 * @var \Illuminate\Contracts\Config\Repository
28
	 */
29
	private $config;
30
31
	/**
32
	 * @var array
33
	 */
34
	private $i18n = array();
35
36
37
	/**
38
	 * Initializes the object
39
	 *
40
	 * @param \Illuminate\Contracts\Config\Repository $config Configuration object
41
	 * @param \Aimeos\Shop\Base\Aimeos $aimeos Aimeos object
42
	 */
43
	public function __construct( \Illuminate\Contracts\Config\Repository $config, \Aimeos\Shop\Base\Aimeos $aimeos )
44
	{
45
		$this->aimeos = $aimeos;
46
		$this->config = $config;
47
	}
48
49
50
	/**
51
	 * Creates new translation objects.
52
	 *
53
	 * @param array $languageIds List of two letter ISO language IDs
54
	 * @return \Aimeos\MW\Translation\Iface[] List of translation objects
55
	 */
56
	public function get( array $languageIds )
57
	{
58
		$i18nPaths = $this->aimeos->get()->getI18nPaths();
59
60
		foreach( $languageIds as $langid )
61
		{
62
			if( !isset( $this->i18n[$langid] ) )
63
			{
64
				$i18n = new \Aimeos\MW\Translation\Gettext( $i18nPaths, $langid );
65
66
				if( $this->config->get( 'shop.apc_enabled', false ) == true ) {
67
					$i18n = new \Aimeos\MW\Translation\Decorator\APC( $i18n, $this->config->get( 'shop.apc_prefix', 'laravel:' ) );
68
				}
69
70
				if( $this->config->has( 'shop.i18n.' . $langid ) ) {
71
					$i18n = new \Aimeos\MW\Translation\Decorator\Memory( $i18n, $this->config->get( 'shop.i18n.' . $langid ) );
72
				}
73
74
				$this->i18n[$langid] = $i18n;
75
			}
76
		}
77
78
		return $this->i18n;
79
	}
80
}