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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
<?php
// definition
class l10n
{
public static $t;
/**
* Load langs/$lang.lang into global $_t array.
*
* @param string $lang
*
* @return void
*/
function load($lang) {
global $_t;
if (!is_array($_t))
$_t = array();
$lang_file = __DIR__ . '/langs/' . $lang . '.lang';
if (file_exists($lang_file)) {
$f = file($lang_file);
foreach ($f as $k => $v) {
if (substr($v, 0, 1) == ';' && !empty($f[$k+1])) {
$_t[trim(substr($v, 1))] = trim($f[$k+1]);
}
}
}
}
/**
* Get value for key $s in global array $_t.
*
* @param string $s
*
* @return string
*/
function _t($s) {
if (trim($s) == '')
return '';
global $_t;
return array_key_exists($s, $_t) ? $_t[$s] : $s;
}
}
/**
* Produce navigation HTML code.
*
* @param boolean $wrap = false should it be wrapped in a <header id="nav" /> element?
* @param string $lang = 'en'
* @param string $inject = null
* @param string $vhost = '//www.mageia.org'
*
* @return string HTML code
*/
function _mgnav_html($wrap = false, $lang = 'en', $inject = null, $vhost = '//www.mageia.org')
{
$lang = _lang_check($lang);
l10n::load($lang);
$tn = array(
array('mageia', '$S/$L/map/', 'Mageia', l10n::_t('Go to mageia.org site map.')),
array('about', '$S/$L/about/', l10n::_t('About us', $_t), l10n::_t('Learn more about Mageia.')),
array('downloads', '$S/$L/downloads/', l10n::_t('Downloads', $_t), l10n::_t('Download Mageia ISO and updates.')),
array('support', '$S/$L/support/', l10n::_t('Support', $_t), l10n::_t('Get support from Mageia community.')),
array('community', '$S/$L/community/', l10n::_t('Community', $_t), l10n::_t('')),
array('contribute', '$S/$L/contribute/', l10n::_t('Contribute', $_t), l10n::_t('You too can build Mageia with us!')),
array('you', '//identity.mageia.org/', l10n::_t('You', $_t), l10n::_t('Your Mageia online account.'))
// <search>
);
$s = array();
foreach ($tn as $i) {
$s[] = sprintf('<li><a href="%s" class="%s" title="%s">%s</a></li>',
str_replace(
array('$L', '$S'),
array($lang, $vhost),
$i[1]
),
$i[0],
$i[3],
$i[2]
);
}
if (!is_null($inject))
$s[] = sprintf('<li>%s</li>', $inject);
$s = implode($s);
$h = sprintf('<!--googleoff: all--><nav id="mgnav"><ul id="nav">%s</ul></nav><!--googleon: all-->', $s);
if ($wrap)
$h = sprintf('<header id="hmgn">%s</header>', $h);
return $h;
}
/**
* Returns CSS definition ready to be inserted into a HTML document.
*
* @return string
*/
function _mgnav_style()
{
return '<style>' . file_get_contents(__DIR__ . '/css/source.css') . '</style>';
}
/**
* Get the primary language subtag only.<p></p>
*/
function _lang_check($s = null)
{
if (!is_null($s)) {
$sub = explode('-', $s);
$sub = strtolower($sub[0]);
}
$supported = array(
'cs',
'de',
'el', 'en', 'eo', 'es', 'et',
'fi', 'fr',
'it',
'lv',
'nb', 'nl',
'pl', 'pt', 'pt-br',
'ro', 'ru',
'sl',
'tr',
'uk',
'zh-cn', 'zh-tw'
);
if (in_array($s, $supported))
return $s;
if (in_array($sub, $supported))
return $s;
return 'en';
}
|