@@ -27,22 +27,22 @@ discard block |
||
| 27 | 27 | * @param bool $use_base |
| 28 | 28 | */ |
| 29 | 29 | protected static function checkLoad($custom_key = null, $force_reload = false, $use_base = false) { |
| 30 | - if($force_reload) self::dropInstance(); |
|
| 30 | + if ($force_reload) self::dropInstance(); |
|
| 31 | 31 | self::$locale = I18nHelper::extractLocale(Security::getInstance()->getSessionKey(I18nHelper::PSFS_SESSION_LANGUAGE_KEY)); |
| 32 | 32 | self::$generate = (boolean)Config::getParam('i18n.autogenerate', false); |
| 33 | - if(!$use_base) { |
|
| 33 | + if (!$use_base) { |
|
| 34 | 34 | $custom_key = $custom_key ?: Security::getInstance()->getSessionKey(self::CUSTOM_LOCALE_SESSION_KEY); |
| 35 | 35 | } |
| 36 | - if(null !== $custom_key) { |
|
| 37 | - Logger::log('[' . self::class . '] Custom key detected: ' . $custom_key, LOG_INFO); |
|
| 38 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $custom_key, self::$locale . '.json']); |
|
| 39 | - } else { |
|
| 40 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale . '.json']); |
|
| 36 | + if (null !== $custom_key) { |
|
| 37 | + Logger::log('['.self::class.'] Custom key detected: '.$custom_key, LOG_INFO); |
|
| 38 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $custom_key, self::$locale.'.json']); |
|
| 39 | + }else { |
|
| 40 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', self::$locale.'.json']); |
|
| 41 | 41 | } |
| 42 | - if(file_exists(self::$filename)) { |
|
| 43 | - Logger::log('[' . self::class . '] Custom locale detected: ' . $custom_key . ' [' . self::$locale . ']', LOG_INFO); |
|
| 42 | + if (file_exists(self::$filename)) { |
|
| 43 | + Logger::log('['.self::class.'] Custom locale detected: '.$custom_key.' ['.self::$locale.']', LOG_INFO); |
|
| 44 | 44 | self::$translations = json_decode(file_get_contents(self::$filename), true); |
| 45 | - } elseif(null !== $custom_key) { |
|
| 45 | + } elseif (null !== $custom_key) { |
|
| 46 | 46 | self::checkLoad(null, $force_reload, true); |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public static function _($message, $custom_key = null, $force_reload = false) { |
| 85 | 85 | self::checkLoad($custom_key, $force_reload); |
| 86 | - if(array_key_exists($message, self::$translations)) { |
|
| 87 | - $translation = self::$translations[$message]; |
|
| 88 | - } else { |
|
| 86 | + if (array_key_exists($message, self::$translations)) { |
|
| 87 | + $translation = self::$translations[$message]; |
|
| 88 | + }else { |
|
| 89 | 89 | $translation = gettext($message); |
| 90 | 90 | } |
| 91 | - if(self::$generate) { |
|
| 91 | + if (self::$generate) { |
|
| 92 | 92 | self::generate($message, $translation); |
| 93 | 93 | } |
| 94 | 94 | return $translation; |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @param string $translation |
| 100 | 100 | */ |
| 101 | 101 | protected static function generate($message, $translation) { |
| 102 | - if(!array_key_exists($message, self::$translations)) { |
|
| 102 | + if (!array_key_exists($message, self::$translations)) { |
|
| 103 | 103 | self::$translations[$message] = $translation; |
| 104 | 104 | } |
| 105 | 105 | file_put_contents(self::$filename, json_encode(array_unique(self::$translations), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); |
@@ -27,7 +27,9 @@ |
||
| 27 | 27 | * @param bool $use_base |
| 28 | 28 | */ |
| 29 | 29 | protected static function checkLoad($custom_key = null, $force_reload = false, $use_base = false) { |
| 30 | - if($force_reload) self::dropInstance(); |
|
| 30 | + if($force_reload) { |
|
| 31 | + self::dropInstance(); |
|
| 32 | + } |
|
| 31 | 33 | self::$locale = I18nHelper::extractLocale(Security::getInstance()->getSessionKey(I18nHelper::PSFS_SESSION_LANGUAGE_KEY)); |
| 32 | 34 | self::$generate = (boolean)Config::getParam('i18n.autogenerate', false); |
| 33 | 35 | if(!$use_base) { |