]>
git.p6c8.net - jirafeau_project.git/blob - lib/lang.php
cc0a9acb7f84a58bc621fefbb96ae185cbaa7516
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 function t($string_id)
22 $r = t_in($string_id, t_select_lang());
24 $r = t_in($string_id, "en");
26 return "FIX ME: " . $string_id;
32 function t_select_lang() {
33 $cfg = $GLOBALS['cfg'];
34 if (strcmp($cfg['lang'], 'auto') != 0) {
37 else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
38 return substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
44 function t_in($string_id, $lang) {
45 $trans = t_get_json($lang);
46 if ($trans === false) {
49 if (!array_key_exists($string_id, $trans)) {
52 return $trans[$string_id];
55 function t_get_raw_json($lang) {
56 $p = JIRAFEAU_ROOT
. "lib/locales/$lang.json";
57 if (!file_exists($p)) {
60 $json = file_get_contents($p);
61 if ($json === false) {
67 function t_get_json($lang) {
68 $raw_j = t_get_raw_json($lang);
69 $array = json_decode($raw_j, true);
70 if ($array === null) {
76 function json_lang_generator($lang) {
79 $r = t_get_raw_json(t_select_lang());
81 $r = t_get_raw_json($lang);
83 return $r === false ?
"{}" : $r;
patrick-canterino.de