/[web]/nav/lib.php
ViewVC logotype

Contents of /nav/lib.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1257 - (show annotations) (download)
Mon May 28 09:13:59 2012 UTC (11 years, 10 months ago) by rda
File size: 3631 byte(s)
return the right sub language
1 <?php
2 // definition
3
4 class l10n
5 {
6 public static $t;
7
8 /**
9 * Load langs/$lang.lang into global $_t array.
10 *
11 * @param string $lang
12 *
13 * @return void
14 */
15 function load($lang) {
16 $lang_file = __DIR__ . '/langs/' . $lang . '.lang';
17 if (file_exists($lang_file)) {
18 global $_t;
19 $f = file($lang_file);
20 foreach ($f as $k => $v) {
21 if (substr($v, 0, 1) == ';' && !empty($f[$k+1])) {
22 $_t[trim(substr($v, 1))] = trim($f[$k+1]);
23 }
24 }
25 }
26 }
27
28 /**
29 * Get value for key $s in global array $_t.
30 *
31 * @param string $s
32 *
33 * @return string
34 */
35 function _t($s) {
36 if (trim($s) == '')
37 return '';
38
39 global $_t;
40
41 return array_key_exists($s, $_t) ? $_t[$s] : $s;
42 }
43 }
44
45 /**
46 * Produce navigation HTML code.
47 *
48 * @param boolean $wrap = false should it be wrapped in a <header id="nav" /> element?
49 * @param string $lang = 'en'
50 * @param string $inject = null
51 * @param string $vhost = '//www.mageia.org'
52 *
53 * @return string HTML code
54 */
55 function _mgnav_html($wrap = false, $lang = 'en', $inject = null, $vhost = '//www.mageia.org')
56 {
57 $lang = _lang_check($lang);
58
59 l10n::load($lang);
60
61 $tn = array(
62 array('mageia', '$S/$L/map/', 'Mageia', l10n::_t('Go to mageia.org site map.')),
63 array('about', '$S/$L/about/', l10n::_t('About&nbsp;us', $_t), l10n::_t('Learn more about Mageia.')),
64 array('downloads', '$S/$L/downloads/', l10n::_t('Downloads', $_t), l10n::_t('Download Mageia ISO and updates.')),
65 array('support', '$S/$L/support/', l10n::_t('Support', $_t), l10n::_t('Get support from Mageia community.')),
66 array('community', '$S/$L/community/', l10n::_t('Community', $_t), l10n::_t('')),
67 array('contribute', '$S/$L/contribute/', l10n::_t('Contribute', $_t), l10n::_t('You too can build Mageia with us!')),
68 array('you', '//identity.mageia.org/', l10n::_t('You', $_t), l10n::_t('Your Mageia online account.'))
69 // <search>
70 );
71
72 $s = array();
73 foreach ($tn as $i) {
74 $s[] = sprintf('<li><a href="%s" class="%s" title="%s">%s</a></li>',
75 str_replace(
76 array('$L', '$S'),
77 array($lang, $vhost),
78 $i[1]
79 ),
80 $i[0],
81 $i[3],
82 $i[2]
83 );
84 }
85
86 if (!is_null($inject))
87 $s[] = sprintf('<li>%s</li>', $inject);
88
89 $s = implode($s);
90 $h = sprintf('<nav id="mgnav"><ul id="nav">%s</ul></nav>', $s);
91
92 if ($wrap)
93 $h = sprintf('<header id="hmgn">%s</header>', $h);
94
95 return $h;
96 }
97
98 /**
99 * Returns CSS definition ready to be inserted into a HTML document.
100 *
101 * @return string
102 */
103 function _mgnav_style()
104 {
105 return '<style>' . file_get_contents(__DIR__ . '/css/source.css') . '</style>';
106 }
107
108 /**
109 * Get the primary language subtag only.<p></p>
110 */
111 function _lang_check($s = null)
112 {
113 if (is_null($s))
114 return 'en';
115
116 $supported = array(
117 'cs',
118 'de',
119 'el', 'en', 'eo', 'es', 'et',
120 'fi', 'fr',
121 'it',
122 'lv',
123 'nb', 'nl',
124 'pl', 'pt', 'pt-br',
125 'ro', 'ru',
126 'sl',
127 'tr',
128 'uk',
129 'zh-cn', 'zh-tw'
130 );
131
132 if (in_array($s, $supported))
133 return $s;
134
135 $sub = explode('-', $s);
136 $sub = strtolower($sub[0]);
137
138 if (in_array($sub, $supported))
139 return $sub;
140
141 return 'en';
142 }

  ViewVC Help
Powered by ViewVC 1.1.30