I18n   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 47
rs 10
wmc 7

2 Methods

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