1 |
1902
|
darkviper
|
<?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 |
|
|
* TranslateAdaptorWb3Mysql.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$
|
30 |
|
|
* @link $HeadURL$
|
31 |
|
|
* @lastmodified $Date$
|
32 |
|
|
* @since File available since 12.05.2013
|
33 |
|
|
* @description Loads translation table from MySQL Language table<br />
|
34 |
|
|
* Can handle Languagecodes like 'de_DE_BAY' (2ALPHA_2ALPHA_2-4ALNUM)
|
35 |
|
|
*/
|
36 |
|
|
|
37 |
|
|
class TranslateAdaptorWb3Mysql implements TranslateAdaptorInterface {
|
38 |
|
|
|
39 |
|
|
protected $sAddon = '';
|
40 |
|
|
protected $sFilePath = '';
|
41 |
|
|
private $_oDb = null;
|
42 |
|
|
private $_sTableName = 'translations';
|
43 |
|
|
/**
|
44 |
|
|
* Constructor
|
45 |
|
|
* @param string descriptor of the Addon (i.e. '' || 'modules\myAddon'
|
46 |
|
|
*/
|
47 |
|
|
public function __construct($sAddon = '')
|
48 |
|
|
{
|
49 |
|
|
$this->_oDb = WbDatabase::getInstance();
|
50 |
|
|
$this->sAddon = $sAddon;
|
51 |
|
|
}
|
52 |
|
|
/**
|
53 |
|
|
* Load languagefile
|
54 |
|
|
* @param string $sLangCode
|
55 |
|
|
* @return array|bool an array of translations or FALSE on error
|
56 |
|
|
*/
|
57 |
|
|
public function loadLanguage($sLangCode)
|
58 |
|
|
{
|
59 |
|
|
$aTranslations = array();
|
60 |
|
|
$sql = 'SELECT `keyword`, `value` '
|
61 |
|
|
. 'FROM `'.$this->_oDb->getTablePrefix.$this->_sTableName.'` '
|
62 |
|
|
. 'WHERE `addon`=\''.$this->sAddon.'\' '
|
63 |
|
|
. 'AND `lang` LIKE \''.addcslashes($sLangCode ,'_?').'\'';
|
64 |
|
|
if(($oTransSet = $this->_oDb->query($sql))) {
|
65 |
|
|
while($aTrans = $oTransSet->fetchRow(MYSQL_ASSOC)) {
|
66 |
|
|
$aTranslations[] = $aTrans;
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
return $aTranslations;
|
70 |
|
|
}
|
71 |
|
|
/**
|
72 |
|
|
* Find first existing language
|
73 |
|
|
* @return string Code of first found basic language
|
74 |
|
|
*/
|
75 |
|
|
public function findFirstLanguage()
|
76 |
|
|
{
|
77 |
|
|
$sql = 'SELECT `lang` '
|
78 |
|
|
. 'FROM `'.$this->_oDb->getTablePrefix.$this->_sTableName.'` '
|
79 |
|
|
. 'WHERE `addon`=\''.$this->sAddon.'\' '
|
80 |
|
|
. 'AND `lang` LIKE \'__\'';
|
81 |
|
|
$sfirstMatch = $this->_oDb->get_one($sql);
|
82 |
|
|
return ($sfirstMatch ? $sfirstMatch : 'en');
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
}
|
86 |
|
|
// end of class TranslateAdaptorWb3Mysql
|