1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-07-05 16:04:24 +03:00
ifhub.club/engine/modules/lang/Lang.class.php

118 lines
3.1 KiB
PHP
Raw Normal View History

<?php
2008-11-16 01:11:15 +02:00
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
/**
* Модуль поддержки языковых файлов
*
*/
class LsLang extends Module {
2008-11-16 01:11:15 +02:00
protected $sCurrentLang;
protected $sLangPath;
2008-11-16 01:11:15 +02:00
protected $aLangMsg=array();
/**
* Инициализация модуля
*
*/
public function Init() {
$this->sCurrentLang = Config::Get('lang.current');
$this->sLangPath = Config::Get('lang.path');
2008-11-16 01:11:15 +02:00
$this->InitLang();
}
/**
* Инициализирует языковой файл
*
*/
protected function InitLang() {
/**
* Если используется кеширование через memcaсhed, то сохраняем данные языкового файла в кеш
*/
if (Config::Get('sys.cache.type')=='memory') {
2008-11-16 01:11:15 +02:00
if (false === ($this->aLangMsg = $this->Cache_Get("lang_{$this->sCurrentLang}"))) {
$this->LoadLangFiles();
2008-11-16 01:11:15 +02:00
$this->Cache_Set($this->aLangMsg, "lang_{$this->sCurrentLang}", array(), 60*60);
}
} else {
$this->LoadLangFiles();
2008-11-16 01:11:15 +02:00
}
/**
* Загружаем в шаблон
*/
$this->Viewer_Assign('aLang',$this->aLangMsg);
}
/**
* Загружает текстовки из языковых файлов
*
*/
protected function LoadLangFiles() {
$this->aLangMsg=include($this->sLangPath.'/'.$this->sCurrentLang.'.php');
/**
* Ищет конфиги языковых файлов и объединяет их с текущим
*/
$sDirConfig=$this->sLangPath.'/modules/';
if ($hDirConfig = opendir($sDirConfig)) {
while (false !== ($sDirModule = readdir($hDirConfig))) {
if ($sDirModule !='.' and $sDirModule !='..' and is_dir($sDirConfig.$sDirModule)) {
$sFileConfig=$sDirConfig.$sDirModule.'/'.$this->sCurrentLang.'.php';
if (file_exists($sFileConfig)) {
$aLangModule=include($sFileConfig);
$this->aLangMsg=array_merge_recursive($this->aLangMsg,$aLangModule);
}
}
}
closedir($hDirConfig);
}
}
2008-11-16 01:11:15 +02:00
/**
* Установить текущий язык
*
* @param unknown_type $sLang
*/
public function SetLang($sLang) {
$this->sCurrentLang=$sLang;
$this->InitLang();
}
/**
* Получить текущий язык
*
* @return unknown
*/
public function GetLang() {
return $this->sCurrentLang;
}
2009-03-30 18:38:56 +03:00
/**
* Получить список текстовок
*
* @return unknown
*/
public function GetLangMsg() {
return $this->aLangMsg;
}
2008-11-16 01:11:15 +02:00
/**
* Получает текстовку по её имени
*
* @param unknown_type $sName
*/
public function Get($sName) {
if (isset($this->aLangMsg[$sName])) {
return $this->aLangMsg[$sName];
}
return 'NOT_FOUND_LANG_TEXT';
}
}
?>