52 |
52 |
*/
|
53 |
53 |
public function loadLanguage($sLangCode)
|
54 |
54 |
{
|
55 |
|
$this->_getAddonPath();
|
|
55 |
$sLanguagePath = $this->_getAddonPath();
|
56 |
56 |
$aTranslations = array();
|
57 |
57 |
$sLangFile = strtolower($sLangCode.'.php');
|
58 |
|
if( ($aDirContent = scandir($this->sFilePath)) !== false) {
|
|
58 |
if( ($aDirContent = scandir($sLanguagePath)) !== false) {
|
59 |
59 |
foreach($aDirContent as $sFile) {
|
60 |
60 |
if($sLangFile === strtolower($sFile)) {
|
61 |
|
$sLangFile = $this->sFilePath.$sFile;
|
|
61 |
$sLangFile = $sLanguagePath.$sFile;
|
62 |
62 |
if(is_readable($sLangFile)) {
|
63 |
63 |
$aTmp = $this->_importArrays($sLangFile);
|
64 |
64 |
$aTranslations = array_merge($aTranslations, $aTmp);
|
... | ... | |
75 |
75 |
*/
|
76 |
76 |
public function findFirstLanguage()
|
77 |
77 |
{
|
78 |
|
$this->_getAddonPath();
|
|
78 |
$sLanguagePath = $this->_getAddonPath();
|
79 |
79 |
// search for first available and readable language file
|
80 |
80 |
$sRetval = '';
|
81 |
|
if(is_readable($this->sFilePath)) {
|
82 |
|
$iterator = new DirectoryIterator($this->sFilePath);
|
|
81 |
if(is_readable($sLanguagePath)) {
|
|
82 |
$iterator = new DirectoryIterator($sLanguagePath);
|
83 |
83 |
foreach ($iterator as $oFileInfo) {
|
84 |
84 |
$sPattern = '/^[a-z]{2,3}\.php/siU';
|
85 |
85 |
if(!preg_match($sPattern, $oFileInfo->getBasename())) { continue; }
|
... | ... | |
97 |
97 |
*/
|
98 |
98 |
private function _getAddonPath()
|
99 |
99 |
{
|
100 |
|
$sAddon = str_replace('\\', '/', $this->sAddon);
|
101 |
|
$sDirname = str_replace('\\', '/', dirname(dirname(__FILE__))).'/';
|
102 |
|
$this->sFilePath = $sDirname.$sAddon.'/languages/';
|
103 |
|
if(!is_readable($this->sFilePath) && (strpos('admin', $this->sAddon) === 0)) {
|
104 |
|
// correct modified admin directory
|
|
100 |
// set environment
|
|
101 |
$sAddon = trim(str_replace('\\', '/', $this->sAddon), '/');
|
|
102 |
$sAppDirname = str_replace('\\', '/', dirname(dirname(__FILE__))).'/';
|
|
103 |
$sLanguagePath = $sAppDirname.$sAddon.'/languages/';
|
|
104 |
if(is_dir($sLanguagePath) && is_readable($sLanguagePath)) {
|
|
105 |
// valid directory found
|
|
106 |
return $sLanguagePath;
|
|
107 |
}
|
|
108 |
if(preg_match('/^admin.*/sU', $sAddon))
|
|
109 |
{
|
|
110 |
// get used acp dirname
|
105 |
111 |
$sTmp = trim(WbAdaptor::getInstance()->AcpDir, '/');
|
106 |
|
$this->sFilePath = $sDirname.preg_replace('/^admin/', $sTmp, $sAddon).'/languages/';
|
107 |
|
if(!is_readable($this->sFilePath)) {
|
108 |
|
throw new TranslationException('missing language definitions in: '.$sAddon.'/languages');
|
|
112 |
// if path starts with 'admin/' then replace with used acp dirname
|
|
113 |
$sLanguagePath = $sAppDirname.preg_replace('/^admin/sU', $sTmp, $sAddon).'/languages/';
|
|
114 |
if(is_dir($sLanguagePath) && is_readable($sLanguagePath)) {
|
|
115 |
// valid directory found
|
|
116 |
return $sLanguagePath;
|
109 |
117 |
}
|
110 |
118 |
}
|
|
119 |
throw new TranslationException('\''.$sAddon.'/languages\' is not a direcory or not readable!');
|
111 |
120 |
}
|
112 |
121 |
/**
|
113 |
122 |
* Import language definitions into array
|
package Translate: creating language path in TranslateAdaptorWbOldStyle with modified admin-path fixed