<?php\r
/*\r
* Jirafeau, your web file repository\r
- * Copyright (C) 2012 Jerome Jutteau <j.jutteau@gmail.com>\r
+ * Copyright (C) 2015 Jerome Jutteau <j.jutteau@gmail.com>\r
*\r
* This program is free software: you can redistribute it and/or modify\r
* it under the terms of the GNU Affero General Public License as\r
\r
global $languages_list;\r
$languages_list = array ('auto' => 'Automatic',\r
+ 'de' => 'Deutsch',\r
'en' => 'English',\r
- 'fr' => 'Français');\r
+ 'fi' => 'Suomi'\r
+ 'fr' => 'Français',\r
+ 'it' => 'Italiano');\r
\r
/* Translation */\r
-function _ ($text)\r
+function t ($text)\r
{\r
$cfg = $GLOBALS['cfg'];\r
$languages_list = $GLOBALS['languages_list'];\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/$l.php");\r
-\r
- foreach ($tr as $o => $t)\r
- if (strcmp ($text, $o) == 0)\r
- return "$t";\r
- }\r
- /* Return original text if no translation is found or already in english. */\r
- return ($text);\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
+ 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
-?>
\ No newline at end of file
+?>\r