]>
git.p6c8.net - jirafeau_mojo42.git/blob - lib/lang.php
3 * Jirafeau, your web file repository
4 * Copyright (C) 2015 Jerome Jutteau <j.jutteau@gmail.com>
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.
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.
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/>.
20 global $languages_list;
21 $languages_list = array('auto' => 'Automatic',
31 'pl' => 'Polszczyzna',
33 'pt_BR' => 'português (Brasil)',
34 'ro' => 'Limba română',
40 function t($string_id)
42 $r = t_in($string_id, t_select_lang());
44 $r = t_in($string_id, "en");
46 return "FIX ME: " . $string_id;
52 function t_select_lang() {
53 $cfg = $GLOBALS['cfg'];
54 if (strcmp($cfg['lang'], 'auto') != 0) {
57 else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
58 return substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
64 function t_in($string_id, $lang) {
65 $trans = t_get_json($lang);
66 if ($trans === false) {
69 if (!array_key_exists($string_id, $trans)) {
72 return $trans[$string_id];
75 function t_get_raw_json($lang) {
76 $p = JIRAFEAU_ROOT
. "lib/locales/$lang.json";
77 if (!file_exists($p)) {
80 $json = file_get_contents($p);
81 if ($json === false) {
87 function t_get_json($lang) {
88 $raw_j = t_get_raw_json($lang);
89 $array = json_decode($raw_j, true);
90 if ($array === null) {
96 function json_lang_generator($lang) {
99 $r = t_get_raw_json(t_select_lang());
101 $r = t_get_raw_json($lang);
103 return $r === false ?
"{}" : $r;
patrick-canterino.de