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

patrick-canterino.de