@@ -19,7 +19,7 @@ |
||
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @param string $default |
22 | - * @return array|mixed|string |
|
22 | + * @return string |
|
23 | 23 | */ |
24 | 24 | public static function extractLocale($default = null) |
25 | 25 | { |
@@ -6,18 +6,18 @@ |
||
6 | 6 | |
7 | 7 | if (!defined('SOURCE_DIR')) define('SOURCE_DIR', __DIR__); |
8 | 8 | if (preg_match('/vendor/', SOURCE_DIR)) { |
9 | - if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); |
|
10 | - if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'src'); |
|
11 | -} else { |
|
12 | - if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..'); |
|
13 | - if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'modules'); |
|
9 | + if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'); |
|
10 | + if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'src'); |
|
11 | +}else { |
|
12 | + if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR.DIRECTORY_SEPARATOR.'..'); |
|
13 | + if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'modules'); |
|
14 | 14 | } |
15 | -if (!defined('VENDOR_DIR')) define('VENDOR_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'vendor'); |
|
16 | -if (!defined('LOG_DIR')) define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
17 | -if (!defined('CACHE_DIR')) define('CACHE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'cache'); |
|
18 | -if (!defined('CONFIG_DIR')) define('CONFIG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'config'); |
|
19 | -if (!defined('WEB_DIR')) define('WEB_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'html'); |
|
20 | -if (!defined('LOCALE_DIR')) define('LOCALE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
15 | +if (!defined('VENDOR_DIR')) define('VENDOR_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'vendor'); |
|
16 | +if (!defined('LOG_DIR')) define('LOG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'logs'); |
|
17 | +if (!defined('CACHE_DIR')) define('CACHE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'cache'); |
|
18 | +if (!defined('CONFIG_DIR')) define('CONFIG_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'config'); |
|
19 | +if (!defined('WEB_DIR')) define('WEB_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'html'); |
|
20 | +if (!defined('LOCALE_DIR')) define('LOCALE_DIR', BASE_DIR.DIRECTORY_SEPARATOR.'locale'); |
|
21 | 21 | |
22 | 22 | |
23 | 23 | /** |
@@ -4,20 +4,42 @@ |
||
4 | 4 | defined('PSFS_START_MEM') or define('PSFS_START_MEM', memory_get_usage()); |
5 | 5 | defined('PSFS_START_TS') or define('PSFS_START_TS', microtime(true)); |
6 | 6 | |
7 | -if (!defined('SOURCE_DIR')) define('SOURCE_DIR', __DIR__); |
|
7 | +if (!defined('SOURCE_DIR')) { |
|
8 | + define('SOURCE_DIR', __DIR__); |
|
9 | +} |
|
8 | 10 | if (preg_match('/vendor/', SOURCE_DIR)) { |
9 | - if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); |
|
10 | - if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'src'); |
|
11 | -} else { |
|
12 | - if (!defined('BASE_DIR')) define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..'); |
|
13 | - if (!defined('CORE_DIR')) define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'modules'); |
|
14 | -} |
|
15 | -if (!defined('VENDOR_DIR')) define('VENDOR_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'vendor'); |
|
16 | -if (!defined('LOG_DIR')) define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
17 | -if (!defined('CACHE_DIR')) define('CACHE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'cache'); |
|
18 | -if (!defined('CONFIG_DIR')) define('CONFIG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'config'); |
|
19 | -if (!defined('WEB_DIR')) define('WEB_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'html'); |
|
20 | -if (!defined('LOCALE_DIR')) define('LOCALE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
11 | + if (!defined('BASE_DIR')) { |
|
12 | + define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..'); |
|
13 | + } |
|
14 | + if (!defined('CORE_DIR')) { |
|
15 | + define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'src'); |
|
16 | + } |
|
17 | + } else { |
|
18 | + if (!defined('BASE_DIR')) { |
|
19 | + define('BASE_DIR', SOURCE_DIR . DIRECTORY_SEPARATOR . '..'); |
|
20 | + } |
|
21 | + if (!defined('CORE_DIR')) { |
|
22 | + define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'modules'); |
|
23 | + } |
|
24 | + } |
|
25 | +if (!defined('VENDOR_DIR')) { |
|
26 | + define('VENDOR_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'vendor'); |
|
27 | +} |
|
28 | +if (!defined('LOG_DIR')) { |
|
29 | + define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
30 | +} |
|
31 | +if (!defined('CACHE_DIR')) { |
|
32 | + define('CACHE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'cache'); |
|
33 | +} |
|
34 | +if (!defined('CONFIG_DIR')) { |
|
35 | + define('CONFIG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'config'); |
|
36 | +} |
|
37 | +if (!defined('WEB_DIR')) { |
|
38 | + define('WEB_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'html'); |
|
39 | +} |
|
40 | +if (!defined('LOCALE_DIR')) { |
|
41 | + define('LOCALE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
42 | +} |
|
21 | 43 | |
22 | 44 | |
23 | 45 | /** |
@@ -19,11 +19,11 @@ discard block |
||
19 | 19 | { |
20 | 20 | $this->locale = I18nHelper::extractLocale('es_ES'); |
21 | 21 | $custom_key = Security::getInstance()->getSessionKey(self::CUSTOM_LOCALE_SESSION_KEY); |
22 | - if(null !== $custom_key) { |
|
23 | - Logger::log('[' . self::class . '] Custom key detected: ' . $custom_key, LOG_INFO); |
|
24 | - $filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $custom_key, $this->locale . '.json']); |
|
25 | - if(file_exists($filename)) { |
|
26 | - Logger::log('[' . self::class . '] Custom locale detected: ' . $custom_key . ' [' . $this->locale . ']', LOG_INFO); |
|
22 | + if (null !== $custom_key) { |
|
23 | + Logger::log('['.self::class.'] Custom key detected: '.$custom_key, LOG_INFO); |
|
24 | + $filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $custom_key, $this->locale.'.json']); |
|
25 | + if (file_exists($filename)) { |
|
26 | + Logger::log('['.self::class.'] Custom locale detected: '.$custom_key.' ['.$this->locale.']', LOG_INFO); |
|
27 | 27 | $this->translations = json_decode(file_get_contents($filename), true); |
28 | 28 | } |
29 | 29 | } |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | { |
45 | 45 | return array( |
46 | 46 | new \Twig_SimpleFilter('trans', function($message) { |
47 | - if(array_key_exists($message, $this->translations)) { |
|
47 | + if (array_key_exists($message, $this->translations)) { |
|
48 | 48 | return $this->translations[$message]; |
49 | - } else { |
|
49 | + }else { |
|
50 | 50 | return gettext($message); |
51 | 51 | } |
52 | 52 | }), |