blob: 65abd385c947c44332c3db494232206f2437a0c1 (
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
77
78
79
80
81
82
83
84
|
<?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;
/**
* Returns singleton
*
* @return Piwik_Translate
*/
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 string the language filename prefix, eg "en" for english
* @throws exception if the language set in the config file is not a valid filename
*/
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.");
}
|