/** * @param string $sKey * * @return string */ public function StaticI18N($sKey) { static $sLang = null; static $aLang = null; if (null === $sLang) { $aList = $this->GetLanguageAndTheme(); $sLang = $aList[0]; } if (null === $aLang) { $aLang = array(); // \RainLoop\Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH.'app/i18n/langs.ini', $aLang); // \RainLoop\Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH.'langs/'.$sLang.'.ini', $aLang); \RainLoop\Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH . 'app/localization/langs.yml', $aLang); \RainLoop\Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH . 'app/localization/webmail/' . $sLang . '.ini', $aLang); $this->Plugins()->ReadLang($sLang, $aLang); } return isset($aLang[$sKey]) ? $aLang[$sKey] : $sKey; }
/** * @param string $sLanguage * @param bool $bAdmin = false * @param bool $bWrapByScriptTag = true * * @return string */ private function compileLanguage($sLanguage, $bAdmin = false, $bWrapByScriptTag = true) { $aResultLang = array(); $sMoment = 'window.moment && window.moment.lang && window.moment.lang(\'en\');'; $sMomentFileName = APP_VERSION_ROOT_PATH . 'app/localization/moment/' . $this->convertLanguageNameToMomentLanguageName($sLanguage) . '.js'; if (\file_exists($sMomentFileName)) { $sMoment = \file_get_contents($sMomentFileName); $sMoment = \preg_replace('/\\/\\/[^\\n]+\\n/', '', $sMoment); } \RainLoop\Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH . 'app/localization/langs.yml', $aResultLang); \RainLoop\Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH . 'app/localization/' . ($bAdmin ? 'admin' : 'webmail') . '/_source.en.yml', $aResultLang); \RainLoop\Utils::ReadAndAddLang(APP_VERSION_ROOT_PATH . 'app/localization/' . ($bAdmin ? 'admin' : 'webmail') . '/' . $sLanguage . '.yml', $aResultLang); $this->Plugins()->ReadLang($sLanguage, $aResultLang); $sLangJs = ''; $aLangKeys = \array_keys($aResultLang); foreach ($aLangKeys as $sKey) { $sString = isset($aResultLang[$sKey]) ? $aResultLang[$sKey] : $sKey; $sLangJs .= '"' . \str_replace('"', '\\"', \str_replace('\\', '\\\\', $sKey)) . '":' . '"' . \str_replace(array("\r", "\n", "\t"), array('\\r', '\\n', '\\t'), \str_replace('"', '\\"', \str_replace('\\', '\\\\', $sString))) . '",'; } $sResult = empty($sLangJs) ? 'null' : '{' . \substr($sLangJs, 0, -1) . '}'; return ($bWrapByScriptTag ? '<script data-cfasync="false">' : '') . 'window.rainloopI18N=' . $sResult . ';' . $sMoment . ($bWrapByScriptTag ? '</script>' : ''); }
/** * @param string $sLang * @param array $sActionName * * @return \RainLoop\PluginsNext\Manager */ public function ReadLang($sLang, &$aLang) { if ($this->bIsEnabled) { foreach ($this->aPlugins as $oPlugin) { if ($oPlugin->UseLangs()) { $sPath = $oPlugin->Path(); \RainLoop\Utils::ReadAndAddLang($sPath . '/langs/en.ini', $aLang); if ('en' !== $sLang) { \RainLoop\Utils::ReadAndAddLang($sPath . '/langs/' . $sLang . '.ini', $aLang); } } } } return $this; }