* GNU Affero General Public License for more details.\r
*\r
* You should have received a copy of the GNU Affero General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.\r
*/\r
\r
- global $languages_list;\r
- $languages_list = array ('auto' => 'Automatic',\r
- 'en' => 'English',\r
- 'fr' => 'Français');\r
+global $languages_list;\r
+$languages_list = array ('auto' => 'Automatic',\r
+ 'de' => 'Deutsch',\r
+ 'en' => 'English',\r
+ 'el' => 'Ελληνικά',\r
+ 'hu' => 'Magyar',\r
+ 'fi' => 'Suomi',\r
+ 'fr' => 'Français',\r
+ 'it' => 'Italiano',\r
+ 'nl' => 'Nederlands',\r
+ 'ro' => 'Limba română',\r
+ 'ru' => 'ру́сский язы́к',\r
+ 'sk' => 'Slovenčina',\r
+ 'zh' => '汉语');\r
\r
/* Translation */\r
function t ($text)\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
+ {\r
+ if (isset ($_SERVER['HTTP_ACCEPT_LANGUAGE']))\r
+ $l = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);\r
+ else\r
+ $l = "en";\r
+ }\r
else\r
$l = $cfg['lang'];\r
\r
if (strcmp ($l, $key) == 0)\r
$found = true;\r
\r
- /* Get translation execpt for english. */\r
- if ($found && strcmp ($l, "en"))\r
- {\r
- /* $tr is defined in this requirement. */\r
- require (JIRAFEAU_ROOT . "lib/lang/lang_$l.php");\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
- foreach ($tr as $o => $t)\r
- if (strcmp ($text, $o) == 0)\r
- return "$t";\r
+ /* Decode JSON. */\r
+ $trans = json_decode ($trans_j, true);\r
+ if ($trans === NULL)\r
+ return $text;\r
+\r
+ /* Try to find translation. */\r
+ if (!array_key_exists ($text, $trans))\r
+ return $text;\r
+\r
+ return $trans[$text];\r
+}\r
+\r
+function json_lang_generator ()\r
+{\r
+ $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
+ {\r
+ if (isset ($_SERVER['HTTP_ACCEPT_LANGUAGE']))\r
+ $l = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);\r
+ else\r
+ $l = "en";\r
}\r
- /* Return original text if no translation is found or already in english. */\r
- return ($text);\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 "{}";\r
+\r
+ /* Open translation file. */\r
+ $trans_j = file_get_contents (JIRAFEAU_ROOT . "lib/locales/$l.json");\r
+ return $trans_j; \r
}\r
\r
?>\r