From: Jerome Jutteau Date: Thu, 16 Jul 2015 21:23:21 +0000 (+0200) Subject: add translation in javascript, closes #23 X-Git-Tag: 1.1~36 X-Git-Url: https://git.p6c8.net/jirafeau.git/commitdiff_plain/d71d969adf8bb35cd6dc8d0ebbe4d7d194e91504?hp=431bebf06dfe7a2a1fecf8d933da97f7a03a358a add translation in javascript, closes #23 Signed-off-by: Jerome Jutteau --- diff --git a/lib/functions_v7.js b/lib/functions.js.php similarity index 95% rename from lib/functions_v7.js rename to lib/functions.js.php index 0e17b50..24be13f 100644 --- a/lib/functions_v7.js +++ b/lib/functions.js.php @@ -1,3 +1,4 @@ + @@ -17,6 +18,21 @@ * along with this program. If not, see . */ +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 = ; + if (lang_array.hasOwnProperty(expr)) + return lang_array[expr]; + return expr; +} + function show_link (url, reference, delete_code, crypt_key, date) { // Upload finished @@ -521,25 +537,25 @@ function milliseconds_to_time_string (milliseconds) 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() diff --git a/lib/lang.php b/lib/lang.php index 0e8203b..225323f 100644 --- a/lib/lang.php +++ b/lib/lang.php @@ -67,4 +67,30 @@ function t ($text) return $trans[$text]; } +function json_lang_generator () +{ + $cfg = $GLOBALS['cfg']; + $languages_list = $GLOBALS['languages_list']; + + /* Detect user's langage if we are in automatic mode. */ + if (strcmp ($cfg['lang'], 'auto') == 0) + $l = substr ($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2); + else + $l = $cfg['lang']; + + /* Is the langage in the list ? */ + $found = false; + foreach ($languages_list as $key => $v) + if (strcmp ($l, $key) == 0) + $found = true; + + /* Don't translate english. */ + if (!($found && strcmp ($l, "en"))) + return "{}"; + + /* Open translation file. */ + $trans_j = file_get_contents (JIRAFEAU_ROOT . "lib/locales/$l.json"); + return $trans_j; +} + ?> diff --git a/lib/locales/template.json b/lib/locales/template.json index 4c06beb..cf7aa81 100644 --- a/lib/locales/template.json +++ b/lib/locales/template.json @@ -105,5 +105,11 @@ "Action": "", "Del link": "", "Del file and links": "", - "Deleted links": "" + "Deleted links": "", + "year": "", + "day": "", + "minute": "", + "hour": "", + "second": "", + "less than a second": "" } diff --git a/lib/template/header.php b/lib/template/header.php index d6dc4b3..275e3f0 100644 --- a/lib/template/header.php +++ b/lib/template/header.php @@ -46,6 +46,6 @@ else - +