Commit 49d60c4d authored by Pascal Engélibert's avatar Pascal Engélibert 🚴 Committed by Pierre-Jean CHANCELLIER
Browse files

Add translation system, en & eo translations

parent ebf9200c
<?php
if(isset($_GET['lang'])) {
if(empty($_GET['lang'])) $langdetect = true;
else $lang = $_GET['lang'];
}
require('lib/locales.php');
include('lib/phpqrcode/qrlib.php');
$api_node = "g1.duniter.fr";
$format_pubkey = "#^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{43,44}$#";
......@@ -23,12 +28,12 @@
$start_date = $_GET["start_date"];
$classcol = "col-4";
if (!isDate($start_date, $format)){
echo "<div>La date de début n'est pas correcte. Vérifiez votre syntaxe.</div>";
echo '<div>'.tr('error_date_start_invalid').'</div>';
exit;
}
$start_date->sub(new DateInterval('P1D'));
}else{
echo "<div>Il manque ladate de début. Vérifiez votre syntaxe.</div>";
echo '<div>'.tr('error_date_start_missing').'</div>';
exit;
}
......@@ -37,10 +42,10 @@
$end_date = $_GET["end_date"];
$classcol = "col-3";
if (!isDate($end_date, $format)){
echo "<div>La date de fin n'est pas correcte. Vérifiez votre syntaxe.</div>";
echo '<div>'.tr('error_date_end_invalid').'</div>';
exit;
}elseif ($end_date < $start_date) {
echo "<div>La date de fin est antérieure à la date de début. Vérifiez votre syntaxe.</div>";
echo '<div>'.tr('error_date_end_missing').'</div>';
exit;
}elseif ($end_date < $today){
$days_left = 0;
......@@ -66,11 +71,11 @@
}
}
else {
echo "<div>La pubkey n'a pas le format attendu. Vérifiez votre syntaxe.</div>";
echo '<div>'.tr('error_pubkey_invalid').'</div>';
exit;
}
}else{
echo "<div>Il manque la pubkey du compte à vérifier. Vérifiez votre syntaxe.</div>";
echo '<div>'.tr('error_pubkey_missing').'</div>';
exit;
}
......@@ -78,14 +83,14 @@
if (!empty($_GET["target"])){
$target = (int)$_GET["target"];
if (!is_int($target)){
echo "<div>La cible n'est pas un entier. Vérifiez votre syntaxe.</div>";
echo '<div>'.tr('error_target_not_int').'</div>';
exit;
}elseif ($target<=0){
echo "<div>La cible est un entier négatif ou nul. Vérifiez votre syntaxe.</div>";
echo '<div>'.tr('error_target_negative').'</div>';
exit;
}
}else{
echo "<div>Il manque le montant à atteindre. Vérifiez votre syntaxe.</div>";
echo '<div>'.tr('error_target_missing').'</div>';
exit;
}
......@@ -150,10 +155,10 @@
$contribution_url = "https://" . $api_node . "/api/#/v1/payment/" . $pubkey . "?amount=10|20|50|100|1000&amp;comment=don&amp;redirect_url=https%3A%252F%252F" . $api_node . "&amp;cancel_url=https%3A%252F%252F" . $api_node;
?>
<!DOCTYPE html>
<html>
<html lang="<?php echo $lang; ?>">
<head>
<meta charset="utf-8">
<title><?php if (!empty($_GET["title"])){echo $_GET["title"];}else{echo "Financement participatif en monnaie libre";} ?></title>
<title><?php if (!empty($_GET["title"])){echo $_GET["title"];}else{echo tr('title_default');} ?></title>
<link rel="stylesheet" href="style.css">
</head>
<body style="color:<?php echo $font_color; ?>;background-color:<?php echo $background_color; ?>;">
......@@ -162,8 +167,8 @@
<div class="row">
<div class="col">
<?php if (!empty($_GET["title"])){echo "<h1>" . $_GET["title"] . "</h1>";} ?>
<?php if ($display_pubkey){echo "<h2 class='pubkey'>Clé publique du compte : " . $pubkey . "</h2>";} ?>
<?php if ($display_qrcode){echo "<img src='" . $qrcode_path . "' alt='QRcode'>";} ?>
<?php if ($display_pubkey){echo '<h2 class="pubkey">' . $tr['label_pubkey'] . ' ' . $pubkey . '</h2>';} ?>
<?php if ($display_qrcode){echo '<img src="' . $qrcode_path . '" alt="'.tr('label_qrcode').'">';} ?>
<div id="progressbar" class="progress border rounded-0" style="border-color:<?php echo $border_color; ?> !important;">
<div class="progress-bar progress-bar-animated" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%;background:<?php echo $progress_color; ?> !important;"><span class="sr-only">0%</span></div>
</div>
......@@ -173,23 +178,23 @@
<div class="column <?php echo $classcol; ?>">
<p><i class="fas fa-chart-pie" aria-hidden="true"></i></p>
<p> <span class="count"><?php echo $percentage?></span><span class="sup">%</span></p>
<h3>atteints</h3>
<h3><?php echo tr('label_reached'); ?></h3>
</div>
<div class="column <?php echo $classcol; ?>">
<p><i class="far fa-user" aria-hidden="true"></i></p>
<p> <span class="count"><?php echo $donors; ?></span></p>
<h3>Donateurs</h3>
<h3><?php echo tr('label_donators'); ?></h3>
</div>
<div class="column <?php echo $classcol; ?>">
<p><i class="far fa-money-bill-alt" aria-hidden="true"></i></p>
<p> <span class="count"><?php echo $total; ?></span><?php if ($unit == "relative"){echo " DU";} ?><span class="sub">Ğ1</span></p>
<h3>Sur un total de <?php echo $target; if ($unit == "relative"){echo " DU";} ?><span class="sub">Ğ1<br></span></h3>
<p> <span class="count"><?php echo $total; ?></span><?php if ($unit == "relative"){echo ' '.tr('ud');} ?><span class="sub">Ğ1</span></p>
<h3><?php echo tr('label_ontotal', array('total'=>$target, 'unit'=>(($unit=='relative') ? tr('ud').'<span class="sub">Ğ1<br></span>' : 'Ğ1'))); ?></h3>
</div>
<?php if (isset($end_date)){ ?>
<div class="column col-3">
<p><i class="far fa-calendar-alt" aria-hidden="true"></i></p>
<p> <span class="count"><?php echo $days_left; ?></span></p>
<h3>jours restants</h3>
<h3><?php echo tr('label_remaining_d'); ?></h3>
</div>
<?php } ?>
</div>
......@@ -197,7 +202,7 @@
<div class="row">
<div class="col">
<a class="btn btn-success" href="<?php echo $contribution_url; ?>" target="_blank" role="button" style="width: 100%;">
<i class="fas fa-check"></i><span>&nbsp;Contribuez maintenant</span>
<i class="fas fa-check"></i><span>&nbsp;<?php echo tr('contribute'); ?></span>
</a>
</div>
</div>
......@@ -220,14 +225,14 @@
data: {
labels: <?php echo json_encode($array_dates); ?>,
datasets: [{
label: 'Evolution du financement',
label: "<?php echo tr('graph_title'); ?>",
steppedLine: false,
data: data,
borderColor: '#0099FF',
fill: false,
},
{
label: 'Objectif',
label: "<?php echo tr('graph_target'); ?>",
steppedLine: false,
data: Array.apply(null, new Array(<?php echo count($array_dates); ?>)).map(Number.prototype.valueOf, <?php echo $target; ?>),
borderColor: 'rgb(255, 99, 132)',
......@@ -259,4 +264,4 @@
});
</script>
</body>
</html>
\ No newline at end of file
</html>
<?php
# Autodetect browser language
if(isset($langdetect) and $langdetect) {
$langd = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
# Client can modify HTTP headers and modify the file path
# So we must verify $langd
if(preg_match('#[a-zA-Z_]{2}#i', $langd))
$lang = $langd;
}
if(isset($lang) and file_exists(getcwd().'/locales/'.$lang.'.tr.php')) {}
else $lang = 'fr';
require('locales/'.$lang.'.tr.php');
function bparse($text, $vars) {
foreach($vars as $var1 => $var2) {
$text = str_replace('{{'.$var1.'}}', $var2, $text);
}
return $text;
}
function tr($tkey, $vars=array()) {
global $ttr;
if(isset($ttr[$tkey])) return bparse($ttr[$tkey], $vars);
return '';
}
?>
<?php
$ttr = array(
'error_date_start_invalid' => 'Invalid start date. Please check your syntax.',
'error_date_start_missing' => 'Missing start date. Please check your syntax.',
'error_date_end_invalid' => 'Invalid end date. Please check your syntax.',
'error_date_end_anterior' => 'End date is anterior to start date. Please check your syntax.',
'error_pubkey_invalid' => 'Invalid pubkey. Please check your syntax.',
'error_pubkey_missing' => 'Missing pubkey. Please check your syntax.',
'error_target_not_int' => 'Target is not integer. Please check your syntax.',
'error_target_negative' => 'Target is negative or null. Please check your syntax.',
'error_target_missing' => 'Missing target. Please check your syntax.',
'title_default' => 'Crowdfunding in libre currency',
'label_pubkey' => 'Accout pubkey:',
'label_qrcode' => 'QRcode',
'label_reached' => 'reached',
'label_donators' => 'Donators',
'ud' => 'UD',
'label_ontotal' => 'Over a total of {{total}} {{unit}}',
'label_remaining_d' => 'days remaining',
'label_contribute' => 'Contribute now',
'graph_title' => 'Evolution of the funding',
'graph_target' => 'Target'
);
?>
<?php
$ttr = array(
'error_date_start_invalid' => 'Erara dato de komenciĝo. Kontrolu vian sintakson.',
'error_date_start_missing' => 'Mankanta dato de komenciĝo. Kontrolu vian sintakson.',
'error_date_end_invalid' => 'Erara fin-dato. Kontrolu vian sintakson.',
'error_date_end_anterior' => 'Fin-dato antaŭanta la daton de komenciĝon. Kontrolu vian sintakson.',
'error_pubkey_invalid' => 'Erara publik-ŝlosilo. Kontrolu vian sintakson.',
'error_pubkey_missing' => 'Mankanta publik-ŝlosilo. Kontrolu vian sintakson.',
'error_target_not_int' => 'Neentjera celo. Kontrolu vian sintakson.',
'error_target_negative' => 'Negativa aŭ nula celo. Kontrolu vian sintakson.',
'error_target_missing' => 'Mankanta celo. Kontrolu vian sintakson.',
'title_default' => 'Liber-mona amasfinancado',
'label_pubkey' => 'Publik-ŝlosilo de la konto:',
'label_qrcode' => 'QRcode',
'label_reached' => 'atingitaj',
'label_donators' => 'Donantoj',
'ud' => 'UD',
'label_ontotal' => 'Celo: {{total}} {{unit}}',
'label_remaining_d' => 'tagoj restas',
'label_contribute' => 'Kontribuu nun',
'graph_title' => 'Evoluo de la financado',
'graph_target' => 'Celo'
);
?>
<?php
$ttr = array(
'error_date_start_invalid' => 'La date de début est incorrecte. Vérifiez votre syntaxe.',
'error_date_start_missing' => 'Il manque la date de début. Vérifiez votre syntaxe.',
'error_date_end_invalid' => 'La date de fin est incorrecte. Vérifiez votre syntaxe.',
'error_date_end_anterior' => 'La date de fin est antérieure à la date de début. Vérifiez votre syntaxe.',
'error_pubkey_invalid' => 'La clé publique n\'a pas le format attendu. Vérifiez votre syntaxe.',
'error_pubkey_missing' => 'Il manque la clé publique du compte à vérifier. Vérifiez votre syntaxe.',
'error_target_not_int' => 'La cible n\'est pas un entier. Vérifiez votre syntaxe.',
'error_target_negative' => 'La cible est un entier négatif ou nul. Vérifiez votre syntaxe.',
'error_target_missing' => 'Il manque le montant à atteindre. Vérifiez votre syntaxe.',
'title_default' => 'Financement participatif en monnaie libre',
'label_pubkey' => 'Clé publique du compte&nbsp;:',
'label_qrcode' => 'QRcode',
'label_reached' => 'atteints',
'label_donators' => 'Donateurs',
'ud' => 'DU',
'label_ontotal' => 'Sur un total de {{total}} {{unit}}',
'label_remaining_d' => 'jours restants',
'label_contribute' => 'Contribuez maintenant',
'graph_title' => 'Évolution du financement',
'graph_target' => 'Objectif'
);
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment