_langDataFallback = parse_ini_file(PATH_ABSOLUTE.'/i18n/eng.ini'); if(!$this->_langDataFallback) { Summoner::sysLog('[ERROR] Missing fallback language file!'); } if(defined('FRONTEND_LANGUAGE')) { $this->_iso3 = FRONTEND_LANGUAGE['iso3']; $this->_iso2 = FRONTEND_LANGUAGE['iso2']; $_langFile = PATH_ABSOLUTE.'/i18n/'.$this->_iso3.'.ini'; if(file_exists($_langFile)) { $_langData = parse_ini_file($_langFile); if($_langData !== false) { $this->_langData = $_langData; } } } else { $this->_langData = $this->_langDataFallback; } } public function twoCharLang(): string { return $this->_iso2; } /** * Return text for given key for currently loaded lang * uses vsprintf or sprintf for placeholders in key * * @param string $key * @param mixed $replace * @return string */ public function t(string $key, mixed $replace=''): string { $ret = $key; $_langWorkWith = $this->_langData; if(isset($this->_langData[$key])) { $ret = $this->_langData[$key]; } elseif(!DEBUG && isset($this->_langDataFallback[$key])) { $ret = $this->_langDataFallback[$key]; $_langWorkWith = $this->_langDataFallback; } // the value is another key // the parse_ini_file interpolation with ${} does not work with existing values from the file itself if(str_starts_with($ret, "reuse.")) { $_ret = str_replace("reuse.","",$ret); if(isset($_langWorkWith[$_ret])) { $ret = $_langWorkWith[$_ret]; } } if(!empty($replace)) { if(is_array($replace)) { $ret = vsprintf($ret, $replace); } else { $ret = sprintf($ret, $replace); } } return $ret; } }