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