Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Implement translation mechanism and start french translation
  • Loading branch information
brenard committed Aug 19, 2016
commit 6eecc0f5ccdf2e27459f626be63a78159b168b04
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ data/
tmp/
# Ignore for safety
.htaccess
.htpasswd
.htpasswd
config.inc.php
4 changes: 4 additions & 0 deletions config.inc.php.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

// Set translation language
$language='fr';
23 changes: 23 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
require_once "lib/serversalt.php";
require_once "lib/vizhash_gd_zero.php";

// Load config.inc.php file if exists
if (file_exists('config.inc.php')) include('config.inc.php');

// In case stupid admin has left magic_quotes enabled in php.ini:
if (get_magic_quotes_gpc())
{
Expand Down Expand Up @@ -425,5 +428,25 @@ function processPasteFetch($pasteid)
$page->assign('VERSION',$VERSION);
$page->assign('ERRORMESSAGE',$ERRORMESSAGE);
$page->assign('STATUS',$STATUS);

// Manage translation
$js_lang_file="";

function translate($str, $modifier = null) {
global $lang;
if (isset($lang[$str])) return $lang[$str];
return $str;
}

if (isset($language)) {
if (file_exists("lang/".$language.".php")) {
include "lang/".$language.".php";
}
if (file_exists("lang/".$language.".js")) {
$js_lang_file="lang/".$language.".js";
}
}
$page->assign('lang_file',$js_lang_file);

$page->draw('page');
?>
12 changes: 9 additions & 3 deletions js/zerobin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
* @author sebsauvage
*/

function translate(msg) {
if (typeof(lang) == "object" && typeof(lang[msg]) == "string") return lang[msg];
return msg;
}

// Immediately start random number generator collector.
sjcl.random.startCollectors();

Expand All @@ -20,8 +25,8 @@ function secondsToHuman(seconds)
if (seconds<60*60) { var v=Math.floor(seconds/60); return v+' minute'+((v>1)?'s':''); }
if (seconds<60*60*24) { var v=Math.floor(seconds/(60*60)); return v+' hour'+((v>1)?'s':''); }
// If less than 2 months, display in days:
if (seconds<60*60*24*60) { var v=Math.floor(seconds/(60*60*24)); return v+' day'+((v>1)?'s':''); }
var v=Math.floor(seconds/(60*60*24*30)); return v+' month'+((v>1)?'s':'');
if (seconds<60*60*24*60) { var v=Math.floor(seconds/(60*60*24)); return v+' '+translate('day')+((v>1)?'s':''); }
var v=Math.floor(seconds/(60*60*24*30)); return v+' '+translate('month')+((v>1)?'s':'');
}

/**
Expand Down Expand Up @@ -206,7 +211,7 @@ function displayMessages(key, comments) {
if (comments[0].meta.syntaxcoloring) applySyntaxColoring();

// Display paste expiration.
if (comments[0].meta.expire_date) $('div#remainingtime').removeClass('foryoureyesonly').text('This document will expire in '+secondsToHuman(comments[0].meta.remaining_time)+'.').show();
if (comments[0].meta.expire_date) $('div#remainingtime').removeClass('foryoureyesonly').text(translate('This document will expire in')+' '+secondsToHuman(comments[0].meta.remaining_time)+'.').show();
if (comments[0].meta.burnafterreading) {
$('div#remainingtime').addClass('foryoureyesonly').text('FOR YOUR EYES ONLY. Don\'t close this window, this message can\'t be displayed again.').show();
$('button#clonebutton').hide(); // Discourage cloning (as it can't really be prevented).
Expand Down Expand Up @@ -486,6 +491,7 @@ function newPaste() {
* (We use the same function for paste and reply to comments)
*/
function showError(message) {
message=translate(message);
$('div#status').addClass('errorMessage').text(message);
$('div#replystatus').addClass('errorMessage').text(message);
}
Expand Down
7 changes: 7 additions & 0 deletions lang/fr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
lang={};

lang["Could not decrypt data (Wrong key ?)"]="Impossible de déchiffrer les données (Mauvaise clé ?)";

lang['This document will expire in']="Ce document expirera dans";
lang["month"]="mois";
lang["day"]="jour";
13 changes: 13 additions & 0 deletions lang/fr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

global $lang;
$lang=array();

$lang["ZeroBin is a minimalist, opensource online pastebin where the server has zero knowledge of pasted data."]="ZeroBin est un pastebin minimaliste et libre où le serveur n'a pas connaissance des données collées.";

$lang["Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES."]="Les données sont chiffrées/déchiffrées <i>par le navigateur</i> en utilisant AES 256 bits.";

$lang['More information on the']="Plus d'information sur le";
$lang["project page"]="site du projet";

$lang["Note: This is a test service:"]="Note: Il s'agit d'un service de test :";
11 changes: 6 additions & 5 deletions tpl/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<script src="js/base64.js?{$VERSION|rawurlencode}#"></script>
<script src="js/rawdeflate.js?{$VERSION|rawurlencode}#"></script>
<script src="js/rawinflate.js?{$VERSION|rawurlencode}#"></script>
{if condition="$lang_file!=''"}<script src="{$lang_file}?{$VERSION|rawurlencode}#"></script>{/if}
<script src="js/zerobin.js?{$VERSION|rawurlencode}#"></script>
<link type="text/css" rel="stylesheet" href="js/highlight.styles/monokai.css?{$VERSION|rawurlencode}#">
<script src="js/highlight.pack.js?{$VERSION|rawurlencode}#"></script>
Expand All @@ -23,11 +24,11 @@
</head>
<body>
<div id="aboutbox">
ZeroBin is a minimalist, opensource online pastebin where the server has zero knowledge of pasted data.
Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES.
More information on the <a href="http://sebsauvage.net/wiki/doku.php?id=php:zerobin">project page</a>.<br />
<span style="text-decoration:blink;font-size:10pt;color:#a4b3c4;">&#9654;</span> Note: This is a test service:
Data may be deleted anytime. Kittens will die if you abuse this service.
{"ZeroBin is a minimalist, opensource online pastebin where the server has zero knowledge of pasted data."|translate}
{"Data is encrypted/decrypted <i>in the browser</i> using 256 bits AES."|translate}
{"More information on the"|translate} <a href="http://sebsauvage.net/wiki/doku.php?id=php:zerobin">{"project page"|translate}</a>.<br />
<span style="text-decoration:blink;font-size:10pt;color:#a4b3c4;">&#9654;</span> {"Note: This is a test service:"|translate}
{"Data may be deleted anytime. Kittens will die if you abuse this service."|translate}
</div>
<h1 title="ZeroBin" onclick="window.location.href=scriptLocation();return false;">ZeroBin</h1><br>
<h2>Because ignorance is bliss</h2><br>
Expand Down