blob: d44119cbf8a571e148adff57b2c538b8637b38e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
* @version $Id$
*
* @package Piwik
*/
/**
*
* @package Piwik
*/
class Piwik_Translate
{
static private $instance = null;
static public function getInstance()
{
if (self::$instance == null)
{
$c = __CLASS__;
self::$instance = new $c();
}
return self::$instance;
}
private function __construct()
{
$GLOBALS['Piwik_translations'] = array();
$language = $this->getLanguageToLoad();
$translations = array();
require_once PIWIK_INCLUDE_PATH . "/lang/" . $language .".php";
$this->addTranslationArray($translations);
}
public function addTranslationArray($translation)
{
// we could check that no string overlap here
$GLOBALS['Piwik_translations'] = array_merge($GLOBALS['Piwik_translations'], $translation);
}
/**
* Enter description here...
*
* @return unknown
*/
public function getLanguageToLoad()
{
$language = Zend_Registry::get('config')->Language->current;
if( Piwik_Common::isValidFilename($language))
{
return $language;
}
else
{
throw new Exception("The language selected ('$language') is not a valid language file ");
}
}
}
function Piwik_Translate($index)
{
if(isset($GLOBALS['Piwik_translations'][$index]))
{
return $GLOBALS['Piwik_translations'][$index];
}
throw new Exception("Translation string '$index' not available.");
}
|