]> git.p6c8.net - jirafeau_project.git/blob - lib/lang.php
lib/lang.php: fix typo
[jirafeau_project.git] / lib / lang.php
1 <?php
2 /*
3 * Jirafeau, your web file repository
4 * Copyright (C) 2015 Jerome Jutteau <j.jutteau@gmail.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (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 Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 global $languages_list;
21 $languages_list = array ('auto' => 'Automatic',
22 'de' => 'Deutsch',
23 'en' => 'English',
24 'fr' => 'Français',
25 'it' => 'Italiano');
26
27 /* Translation */
28 function t ($text)
29 {
30 $cfg = $GLOBALS['cfg'];
31 $languages_list = $GLOBALS['languages_list'];
32
33 /* Detect user's langage if we are in automatic mode. */
34 if (strcmp ($cfg['lang'], 'auto') == 0)
35 $l = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
36 else
37 $l = $cfg['lang'];
38
39 /* Is the langage in the list ? */
40 $found = false;
41 foreach ($languages_list as $key => $v)
42 if (strcmp ($l, $key) == 0)
43 $found = true;
44
45 /* Don't translate english. */
46 if (!($found && strcmp ($l, "en")))
47 return $text;
48
49 /* Open translation file. */
50 $trans_j = file_get_contents (JIRAFEAU_ROOT . "lib/locales/$l.json");
51 if ($trans_j === FALSE)
52 return $text;
53
54 /* Decode JSON. */
55 $trans = json_decode ($trans_j, true);
56 if ($trans === NULL)
57 return $text;
58
59 /* Try to find translation. */
60 if (!array_key_exists ($text, $trans))
61 return $text;
62
63 return $trans[$text];
64 }
65
66 ?>

patrick-canterino.de