1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license MIT, http://opensource.org/licenses/MIT |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
6
|
|
|
* @package symfony |
7
|
|
|
* @subpackage Service |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Aimeos\ShopBundle\Service; |
11
|
|
|
|
12
|
|
|
use Symfony\Component\DependencyInjection\Container; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Service providing the internationalization objects |
17
|
|
|
* |
18
|
|
|
* @package symfony |
19
|
|
|
* @subpackage Service |
20
|
|
|
*/ |
21
|
|
|
class I18n |
22
|
|
|
{ |
23
|
|
|
private $container; |
24
|
|
|
private $i18n = array(); |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Initializes the context manager object |
29
|
|
|
* |
30
|
|
|
* @param Container $container Container object to access parameters |
31
|
|
|
*/ |
32
|
|
|
public function __construct( Container $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\Base\Translation\Interface[] List of translation objects |
43
|
|
|
*/ |
44
|
|
|
public function get( array $languageIds ) |
45
|
|
|
{ |
46
|
|
|
$i18nPaths = $this->container->get( 'aimeos' )->get()->getI18nPaths(); |
47
|
|
|
|
48
|
|
|
foreach( $languageIds as $langid ) |
49
|
|
|
{ |
50
|
|
|
if( !isset( $this->i18n[$langid] ) ) |
51
|
|
|
{ |
52
|
|
|
$i18n = new \Aimeos\Base\Translation\Gettext( $i18nPaths, $langid ); |
53
|
|
|
|
54
|
|
|
$apc = (bool) $this->container->getParameter( 'aimeos_shop.apc_enable' ); |
55
|
|
|
$prefix = $this->container->getParameter( 'aimeos_shop.apc_prefix' ); |
56
|
|
|
|
57
|
|
|
if( function_exists( 'apcu_store' ) === true && $apc === true ) { |
58
|
|
|
$i18n = new \Aimeos\Base\Translation\Decorator\APC( $i18n, $prefix ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$translations = $this->container->getParameter( 'aimeos_shop.i18n' ); |
62
|
|
|
|
63
|
|
|
if( isset( $translations[$langid] ) ) { |
64
|
|
|
$i18n = new \Aimeos\Base\Translation\Decorator\Memory( $i18n, $translations[$langid] ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$this->i18n[$langid] = $i18n; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->i18n; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|