@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $locale = $locale ?? self::$locale; |
| 55 | 55 | // Gather always the base translations |
| 56 | 56 | $standardTranslations = []; |
| 57 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $locale . '.json']); |
|
| 57 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $locale.'.json']); |
|
| 58 | 58 | if (file_exists(self::$filename)) { |
| 59 | 59 | $standardTranslations = json_decode(file_get_contents(self::$filename), true); |
| 60 | 60 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | protected static function generateTranslationsKeys($locale) { |
| 69 | 69 | self::$translationsKeys[$locale] = []; |
| 70 | - foreach(self::$translations[$locale] as $key => $value) { |
|
| 70 | + foreach (self::$translations[$locale] as $key => $value) { |
|
| 71 | 71 | $tKey = mb_convert_case($key, MB_CASE_LOWER, "UTF-8"); |
| 72 | 72 | self::$translationsKeys[$locale][$tKey] = $key; |
| 73 | 73 | } |
@@ -86,42 +86,42 @@ discard block |
||
| 86 | 86 | self::$locale = $forceReload ? $session_locale : I18nHelper::extractLocale($session_locale); |
| 87 | 87 | $locale = self::$locale; |
| 88 | 88 | $version = $session->getSessionKey(self::LOCALE_CACHED_VERSION); |
| 89 | - $configVersion = self::$locale . '_' . Config::getParam('cache.var', 'v1'); |
|
| 89 | + $configVersion = self::$locale.'_'.Config::getParam('cache.var', 'v1'); |
|
| 90 | 90 | if ($forceReload) { |
| 91 | 91 | Inspector::stats('[translationsCheckLoad] Force translations reload', Inspector::SCOPE_DEBUG); |
| 92 | 92 | self::dropInstance(); |
| 93 | 93 | $version = null; |
| 94 | 94 | self::$translations[self::$locale] = []; |
| 95 | 95 | } |
| 96 | - if((!array_key_exists($locale, self::$translations) || count(self::$translations[$locale]) === 0) && strlen($locale) === 2) { |
|
| 97 | - $locale = $locale . '_' . strtoupper($locale); |
|
| 98 | - if(array_key_exists($locale, self::$translations)) { |
|
| 96 | + if ((!array_key_exists($locale, self::$translations) || count(self::$translations[$locale]) === 0) && strlen($locale) === 2) { |
|
| 97 | + $locale = $locale.'_'.strtoupper($locale); |
|
| 98 | + if (array_key_exists($locale, self::$translations)) { |
|
| 99 | 99 | self::$translations[self::$locale] = self::$translations[$locale]; |
| 100 | 100 | self::generateTranslationsKeys(self::$locale); |
| 101 | 101 | } |
| 102 | 102 | } |
| 103 | - if(!array_key_exists($locale, self::$translations) || count(self::$translations[$locale]) === 0) { |
|
| 103 | + if (!array_key_exists($locale, self::$translations) || count(self::$translations[$locale]) === 0) { |
|
| 104 | 104 | Inspector::stats('[translationsCheckLoad] Extracting translations', Inspector::SCOPE_DEBUG); |
| 105 | 105 | self::$generate = (boolean)Config::getParam('i18n.autogenerate', false); |
| 106 | - if(null !== $version && $version === $configVersion) { |
|
| 106 | + if (null !== $version && $version === $configVersion) { |
|
| 107 | 107 | Inspector::stats('[translationsCheckLoad] Translations loaded from session', Inspector::SCOPE_DEBUG); |
| 108 | 108 | self::$translations = $session->getSessionKey(self::LOCALE_CACHED_TAG); |
| 109 | - } else { |
|
| 109 | + }else { |
|
| 110 | 110 | if (!$useBase) { |
| 111 | 111 | $customKey = $customKey ?: $session->getSessionKey(self::CUSTOM_LOCALE_SESSION_KEY); |
| 112 | 112 | } |
| 113 | 113 | $standardTranslations = self::extractBaseTranslations(); |
| 114 | 114 | // If the project has custom translations, gather them |
| 115 | 115 | if (null !== $customKey) { |
| 116 | - Logger::log('[' . self::class . '] Custom key detected: ' . $customKey, LOG_INFO); |
|
| 117 | - self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $customKey, $locale . '.json']); |
|
| 116 | + Logger::log('['.self::class.'] Custom key detected: '.$customKey, LOG_INFO); |
|
| 117 | + self::$filename = implode(DIRECTORY_SEPARATOR, [LOCALE_DIR, 'custom', $customKey, $locale.'.json']); |
|
| 118 | 118 | } elseif (!empty($standardTranslations)) { |
| 119 | 119 | self::$translations[$locale] = $standardTranslations; |
| 120 | 120 | self::generateTranslationsKeys($locale); |
| 121 | 121 | } |
| 122 | 122 | // Finally we merge base and custom translations to complete all the i18n set |
| 123 | 123 | if (file_exists(self::$filename)) { |
| 124 | - Logger::log('[' . self::class . '] Custom locale detected: ' . $customKey . ' [' . $locale . ']', LOG_INFO); |
|
| 124 | + Logger::log('['.self::class.'] Custom locale detected: '.$customKey.' ['.$locale.']', LOG_INFO); |
|
| 125 | 125 | self::$translations[$locale] = array_merge($standardTranslations, json_decode(file_get_contents(self::$filename), true)); |
| 126 | 126 | self::generateTranslationsKeys($locale); |
| 127 | 127 | $session->setSessionKey(self::LOCALE_CACHED_TAG, self::$translations); |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | public function getFilters() |
| 149 | 149 | { |
| 150 | 150 | return array( |
| 151 | - new TwigFilter('trans', function ($message) { |
|
| 151 | + new TwigFilter('trans', function($message) { |
|
| 152 | 152 | return self::_($message); |
| 153 | 153 | }), |
| 154 | 154 | ); |
@@ -170,21 +170,21 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | public static function _($message, $customKey = null, $forceReload = false) |
| 172 | 172 | { |
| 173 | - if(0 === count(self::$translations) || $forceReload) { |
|
| 173 | + if (0 === count(self::$translations) || $forceReload) { |
|
| 174 | 174 | self::translationsCheckLoad($customKey, $forceReload); |
| 175 | 175 | } |
| 176 | 176 | // Set default translation to catch missing strings |
| 177 | 177 | $isDebugMode = (bool)Config::getParam('debug', false); |
| 178 | - $translation = (bool)Config::getParam('debug', false) ? 'MISSING_TRANSLATION - ' . self::$locale : $message; |
|
| 178 | + $translation = (bool)Config::getParam('debug', false) ? 'MISSING_TRANSLATION - '.self::$locale : $message; |
|
| 179 | 179 | // Check if the message is already translated ignoring the string case |
| 180 | 180 | $key = mb_convert_case($message, MB_CASE_LOWER, "UTF-8"); |
| 181 | - if(array_key_exists(self::$locale, self::$translationsKeys) && array_key_exists($key, self::$translationsKeys[self::$locale])) { |
|
| 181 | + if (array_key_exists(self::$locale, self::$translationsKeys) && array_key_exists($key, self::$translationsKeys[self::$locale])) { |
|
| 182 | 182 | $message = self::$translationsKeys[self::$locale][$key]; |
| 183 | 183 | } |
| 184 | 184 | // Check if exists |
| 185 | 185 | if (array_key_exists(self::$locale, self::$translations) && array_key_exists($message, self::$translations[self::$locale])) { |
| 186 | 186 | $translation = self::$translations[self::$locale][$message]; |
| 187 | - } else if(!$forceReload && !$isDebugMode) { |
|
| 187 | + }else if (!$forceReload && !$isDebugMode) { |
|
| 188 | 188 | $translation = gettext($message); |
| 189 | 189 | } |
| 190 | 190 | if (self::$generate) { |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | */ |
| 200 | 200 | protected static function generate($message, $translation) |
| 201 | 201 | { |
| 202 | - if(!array_key_exists(self::$locale, self::$translations)) { |
|
| 202 | + if (!array_key_exists(self::$locale, self::$translations)) { |
|
| 203 | 203 | self::$translations[self::$locale] = []; |
| 204 | 204 | self::$translationsKeys[self::$locale] = []; |
| 205 | 205 | } |