+<?php
 /*
  *  Jirafeau, your web file repository
  *  Copyright (C) 2015  Jerome Jutteau <j.jutteau@gmail.com>
  *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+define ('JIRAFEAU_ROOT', dirname (__FILE__) . '/../');
+require (JIRAFEAU_ROOT . 'lib/config.original.php');
+require (JIRAFEAU_ROOT . 'lib/settings.php');
+require (JIRAFEAU_ROOT . 'lib/functions.php');
+require (JIRAFEAU_ROOT . 'lib/lang.php');
+?>
+
+function translate (expr)
+{
+    var lang_array = <?php echo json_lang_generator () ?>;
+    if (lang_array.hasOwnProperty(expr))
+        return lang_array[expr];
+    return expr;
+}
+
 function show_link (url, reference, delete_code, crypt_key, date)
 {
     // Upload finished
     var temp = Math.floor(milliseconds / 1000);
     var years = Math.floor(temp / 31536000);
     if (years) {
-        return years + ' year' + numberEnding(years);
+        return years + ' ' + translate ('year') + numberEnding(years);
     }
     var days = Math.floor((temp %= 31536000) / 86400);
     if (days) {
-        return days + ' day' + numberEnding(days);
+        return days + ' ' + translate ('day') + numberEnding(days);
     }
     var hours = Math.floor((temp %= 86400) / 3600);
     if (hours) {
-        return hours + ' hour' + numberEnding(hours);
+        return hours + ' ' + translate ('hour') + numberEnding(hours);
     }
     var minutes = Math.floor((temp %= 3600) / 60);
     if (minutes) {
-        return minutes + ' minute' + numberEnding(minutes);
+        return minutes + ' ' + translate ('minute') + numberEnding(minutes);
     }
     var seconds = temp % 60;
     if (seconds) {
-        return seconds + ' second' + numberEnding(seconds);
+        return seconds + ' ' + translate ('second') + numberEnding(seconds);
     }
-    return 'less than a second';
+    return translate ('less than a second');
 }
 
 function upload_time_estimation_time()
 
     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
+        $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 "{}";\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