1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
5
|
*
|
6
|
* This program is free software: you can redistribute it and/or modify
|
7
|
* it under the terms of the GNU General Public License as published by
|
8
|
* the Free Software Foundation, either version 3 of the License, or
|
9
|
* (at your option) any later version.
|
10
|
*
|
11
|
* This program is distributed in the hope that it will be useful,
|
12
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
* GNU General Public License for more details.
|
15
|
*
|
16
|
* You should have received a copy of the GNU General Public License
|
17
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
18
|
*/
|
19
|
|
20
|
/**
|
21
|
* TranslationTable.php
|
22
|
*
|
23
|
* @category Core
|
24
|
* @package Core_Translation
|
25
|
* @copyright Werner v.d.Decken <wkl@isteam.de>
|
26
|
* @author Werner v.d.Decken <wkl@isteam.de>
|
27
|
* @license http://www.gnu.org/licenses/gpl.html GPL License
|
28
|
* @version 0.0.1
|
29
|
* @revision $Revision: 1873 $
|
30
|
* @link $HeadURL: svn://isteam.dynxs.de/wb-archiv/branches/2.8.x/wb/framework/TranslateAdaptorWbOldStyle.php $
|
31
|
* @lastmodified $Date: 2013-02-27 01:15:20 +0100 (Wed, 27 Feb 2013) $
|
32
|
* @since File available since 12.01.2013
|
33
|
* @description Loads translation table from old languagefiles before WB-2.9.0.
|
34
|
* Can handle Languagecodes like 'de_DE_BAY' (2ALPHA_2ALPHA_2-4ALNUM)
|
35
|
*/
|
36
|
class TranslateAdaptorWbOldStyle implements TranslateAdaptorInterface {
|
37
|
|
38
|
protected $sAddon = '';
|
39
|
protected $sFilePath = '';
|
40
|
/**
|
41
|
* Constructor
|
42
|
* @param string descriptor of the Addon (i.e. '' || 'modules\myAddon'
|
43
|
*/
|
44
|
public function __construct($sAddon = '')
|
45
|
{
|
46
|
$this->sAddon = $sAddon;
|
47
|
$this->sFilePath = str_replace('\\', '/', dirname(dirname(__FILE__)).'/'.$sAddon);
|
48
|
$this->sFilePath = rtrim($this->sFilePath, '/').'/languages/';
|
49
|
}
|
50
|
/**
|
51
|
* Load languagefile
|
52
|
* @param string $sLangCode
|
53
|
* @return array|bool an array of translations or FALSE on error
|
54
|
*/
|
55
|
public function loadLanguage($sLangCode)
|
56
|
{
|
57
|
$aTranslations = array();
|
58
|
$sLangFile = strtolower($sLangCode.'.php');
|
59
|
if( ($aDirContent = scandir($this->sFilePath)) !== false) {
|
60
|
foreach($aDirContent as $sFile) {
|
61
|
if($sLangFile === strtolower($sFile)) {
|
62
|
$sLangFile = $this->sFilePath.$sFile;
|
63
|
if(is_readable($sLangFile)) {
|
64
|
$aTmp = $this->_importArrays($sLangFile);
|
65
|
$aTranslations = array_merge($aTranslations, $aTmp);
|
66
|
break;
|
67
|
}
|
68
|
}
|
69
|
}
|
70
|
}
|
71
|
return (sizeof($aTranslations) > 0 ? $aTranslations : false);
|
72
|
}
|
73
|
/**
|
74
|
* Find first existing language
|
75
|
* @return string Code of first found basic language
|
76
|
*/
|
77
|
public function findFirstLanguage()
|
78
|
{
|
79
|
// search for first available and readable language file
|
80
|
$sRetval = '';
|
81
|
if(is_readable($this->sFilePath)) {
|
82
|
$iterator = new DirectoryIterator($this->sFilePath);
|
83
|
foreach ($iterator as $oFileInfo) {
|
84
|
$sPattern = '/^[a-z]{2,3}\.php/siU';
|
85
|
if(!preg_match($sPattern, $oFileInfo->getBasename())) { continue; }
|
86
|
if($oFileInfo->isReadable()) {
|
87
|
$sRetval = $oFileInfo->getBasename('.php');
|
88
|
break;
|
89
|
}
|
90
|
}
|
91
|
}
|
92
|
return $sRetval;
|
93
|
}
|
94
|
/**
|
95
|
* Import language definitions into array
|
96
|
* @param string load language from filename
|
97
|
* @return array contains all found translations
|
98
|
*/
|
99
|
private function _importArrays($sLanguageFile)
|
100
|
{
|
101
|
// include the file
|
102
|
include($sLanguageFile);
|
103
|
// get all available loaded vars of this method
|
104
|
$aAllVars = get_defined_vars();
|
105
|
$aLangSections = array();
|
106
|
$aLanguageTable = array();
|
107
|
foreach($aAllVars as $key=>$value) {
|
108
|
// extract the names of arrays from language file
|
109
|
if(is_array($value)) {
|
110
|
$aLangSections[] = $key;
|
111
|
}
|
112
|
}
|
113
|
foreach($aLangSections as $sSection) {
|
114
|
// walk through all arrays
|
115
|
foreach(${$sSection} as $key => $value) {
|
116
|
// and import all found translations
|
117
|
if(!is_array($value)) {
|
118
|
// skip all multiarray definitions from compatibility mode
|
119
|
$aLanguageTable[$sSection.'_'.$key] = $value;
|
120
|
}
|
121
|
}
|
122
|
}
|
123
|
return $aLanguageTable;
|
124
|
}
|
125
|
} // end of class TranslateAdaptorWbOldStyle
|