]> git.p6c8.net - jirafeau_mojo42.git/blob - lib/lang.php
add strict XHTML 1.0 as doctype
[jirafeau_mojo42.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 <https://www.gnu.org/licenses/>.
18 */
19
20 global $languages_list;
21 $languages_list = array ('auto' => 'Automatic',
22 'de' => 'Deutsch',
23 'en' => 'English',
24 'fi' => 'Suomi',
25 'fr' => 'Français',
26 'it' => 'Italiano',
27 'nl' => 'Nederlands',
28 'ro' => 'Limba română',
29 'sk' => 'Slovenčina');
30
31 /* Translation */
32 function t ($text)
33 {
34 $cfg = $GLOBALS['cfg'];
35 $languages_list = $GLOBALS['languages_list'];
36
37 /* Detect user's langage if we are in automatic mode. */
38 if (strcmp ($cfg['lang'], 'auto') == 0)
39 $l = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
40 else
41 $l = $cfg['lang'];
42
43 /* Is the langage in the list ? */
44 $found = false;
45 foreach ($languages_list as $key => $v)
46 if (strcmp ($l, $key) == 0)
47 $found = true;
48
49 /* Don't translate english. */
50 if (!($found && strcmp ($l, "en")))
51 return $text;
52
53 /* Open translation file. */
54 $trans_j = file_get_contents (JIRAFEAU_ROOT . "lib/locales/$l.json");
55 if ($trans_j === FALSE)
56 return $text;
57
58 /* Decode JSON. */
59 $trans = json_decode ($trans_j, true);
60 if ($trans === NULL)
61 return $text;
62
63 /* Try to find translation. */
64 if (!array_key_exists ($text, $trans))
65 return $text;
66
67 return $trans[$text];
68 }
69
70 ?>

patrick-canterino.de