[a-z][a-z])($|\/)/', Base::currentPath(), $match) ) { Lang::set($match['lang']); } } /** * Get language content * * @param string $file = NULL * @param string $str = NULL * @param mixed $changed = NULL * * @return mixed */ public static function select(?string $file = NULL, ?string $str = NULL, $changed = NULL) { $langstr = ''; if( ! isset(self::$lang[$file]) ) { $file = ($getLang = self::get()).'/'.Base::suffix($file, '.php'); $langDir = LANGUAGES_DIR . $file; $commonLangDir = EXTERNAL_LANGUAGES_DIR . $file; if( is_file($langDir) && ! IS::import($langDir) ) { self::$lang[$file] = require $langDir; // @codeCoverageIgnore } elseif( is_file($commonLangDir) && ! IS::import($commonLangDir) ) { self::$lang[$file] = require $commonLangDir; // @codeCoverageIgnore } elseif( ! empty(self::$default) && empty(self::$lang[$file]) ) { self::$lang[$file] = self::getDefault()[$getLang] ?? false; } } if( empty($str) && isset(self::$lang[$file]) ) { return self::$lang[$file]; } elseif( ! empty(self::$lang[$file][$str]) ) { $langstr = self::$lang[$file][$str]; } else { return false; } if( ! is_array($changed) ) { if( strstr($langstr, "%") && ! empty($changed) ) { return str_replace("%", $changed , $langstr); } else { return $langstr; } } else { if( ! empty($changed) ) { $values = []; foreach( $changed as $key => $value ) { $keys[] = $key; $values[] = $value; } return str_replace($keys, $values, $langstr); } else { return $langstr; } } } /** * Sets language * * @param string $l = NULL * * @return bool */ public static function set(?string $l = NULL) : bool { if( empty($l) ) { $l = Config::get('Project', 'language'); } return $_SESSION[In::defaultProjectKey('SystemLanguageData')] = $l; } /** * Get language short code * * @return string */ public static function get() : string { $systemLanguageData = In::defaultProjectKey('SystemLanguageData'); $defaultSystemLanguageData = In::defaultProjectKey('DefaultSystemLanguageData'); $default = Config::get('Project', 'language') ?: 'en'; if( empty($_SESSION[$defaultSystemLanguageData]) ) { $_SESSION[$defaultSystemLanguageData] = $default; } else { // @codeCoverageIgnoreStart if( $_SESSION[$defaultSystemLanguageData] !== $default ) { $_SESSION[$defaultSystemLanguageData] = $default; $_SESSION[$systemLanguageData] = $default; return $default; } // @codeCoverageIgnoreEnd } if( empty($_SESSION[$systemLanguageData]) ) { $_SESSION[$systemLanguageData] = $default; return $default; } else { return $_SESSION[$systemLanguageData]; } } /** * Protected Get Default * * @return mixed */ protected static function getDefault() { $default = self::$default; self::$default = NULL; if( is_string($default) ) { return get_class_vars($default); } elseif( is_object($default) ) { return get_object_vars($default); } else { return false; } } }