+ $cfg = $GLOBALS['cfg'];\r
+ $languages_list = $GLOBALS['languages_list'];\r
+\r
+ /* Detect user's langage if we are in automatic mode. */\r
+ if (strcmp ($cfg['lang'], 'auto') == 0)\r
+ $l = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);\r
+ else\r
+ $l = $cfg['lang'];\r
+\r
+ /* Is the langage in the list ? */\r
+ $found = false;\r
+ foreach ($languages_list as $key => $v)\r
+ if (strcmp ($l, $key) == 0)\r
+ $found = true;\r
+\r
+ /* Don't translate english. */\r
+ if (!($found && strcmp ($l, "en")))\r
+ return $text;\r
+\r
+ /* Open translation file. */\r
+ $trans_j = file_get_contents (JIRAFEAU_ROOT . "lib/locales/$l.json");\r
+ if ($trans_j === FALSE)\r
+ return $text;\r
+\r
+ /* Decode JSON. */\r
+ $trans = json_decode ($trans_j, true);\r
+ error_log(print_r($trans, true));\r
+ if ($trans === NULL)\r
+ return $text;\r
+\r
+ /* Try to find translation. */\r
+ $translation = $trans[$text];\r
+ if (empty ($translation))\r
+ return $text;\r
+\r
+ return $translation;\r