support for localization

This commit is contained in:
Ventricule 2018-02-20 01:16:10 +01:00
commit 9ae9fb6c68
9 changed files with 81 additions and 13 deletions

3
.gitmodules vendored
View file

@ -10,3 +10,6 @@
[submodule "assets/parsedown-extra"]
path = assets/parsedown-extra
url = https://github.com/erusev/parsedown-extra.git
[submodule "assets/spyc"]
path = assets/spyc
url = https://github.com/mustangostang/spyc.git

1
assets/spyc Submodule

@ -0,0 +1 @@
Subproject commit 576c42ecbc9630b52a95da3279f07278572c6b15

View file

@ -152,3 +152,14 @@ button[type=submit] {
cursor: pointer;
border-radius: 2rem;
}
div[class^="lang-"] {
display: none;
}
.current-lang-fr .lang-fr {
display: block;
}
.current-lang-en .lang-en {
display: block;
}

View file

@ -2,17 +2,42 @@
![Libreto](http://libreto.net/assets/images/libretonet.png)
<div class="lang-en" markdown="1">
A Libreto is a collaborative notebook based on [framapad](https://framapad.org).
It can become a mini-website, a workshop logbook or the tool to write a collective book.
Libreto is free and minimal.
No registration, no connection, anyone can write a Libreto.
</div>
<div class="lang-fr" markdown="1">
Un Libreto est un carnet de note collaboratif fondé sur [framapad](https://framapad.org).
Il peut devenir un mini-site, le carnet de bord d'un workshop, le support de rédaction d'un livre collectif ou tout autre chose.
Il peut devenir un mini-site, le carnet de bord d'un workshop ou le support de rédaction d'un livre collectif.
Libreto est libre, gratuit, et minimaliste.
Pas d'inscription, pas de connexion, tout le monde peut éditer un Libreto, comme un wiki.
Pas d'inscription, pas de connexion, tout le monde peut écrire un Libreto.
</div>
<div class="colophon" markdown="1">
<div class="lang-en" markdown="1">
A project initiated by [Pierre Tandille](http://lecollecteur.fr)
Libreto is under [GNU/GPLv3 License](https://www.gnu.org/licenses/gpl-3.0.en.html)
Use and modify on [GitHub](https://github.com/Ventricule/libreto)
</div>
<div class="lang-fr" markdown="1">
Un projet initié par [Pierre Tandille](http://lecollecteur.fr).
Libreto est sous [licence GNU/GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html).
N'hésitez pas à participer sur [GitHub](https://github.com/Ventricule/libreto).
</div>
</div>

View file

@ -0,0 +1,3 @@
create-libreto:
fr: Créer un Libreto
en: Create Libreto

View file

@ -4,3 +4,4 @@ $instance_name = "Libreto";
$pads_host = "https://annuel2.framapad.org";
$pads_params = "?showControls=true&showChat=false&showLineNumbers=false&useMonospaceFont=false";
$use_subdomain = 0; // if set to TRUE, libreto adress will look like mysite.libreto.net — if FALSE, they will look like libreto.net/mysite
$fallback_language = "en"; // Language fallback if local translation not set

View file

@ -1,5 +1,8 @@
<?php
include('snippets/functions.php');
$user_language = get_user_language();
$translation = load_translation_file();
if(isset($_POST['new_name'])):
if($new_name = $_POST['new_name']) :
header('Location: ' . 'http://' . $_SERVER["SERVER_NAME"] . '/' . urlencode($new_name) );
@ -19,7 +22,7 @@ endif;
<link rel="stylesheet" href="/assets/style-index.css">
</head>
<body>
<body class="current-lang-<?= get_user_language() ?>">
<article>
<?php
$markdown = file_get_contents("assets/texts/homepage.md");
@ -30,7 +33,7 @@ endif;
<div class="create_libreto">
<form action="" method="POST">
<input type="input" autofocus="autofocus" onfocus="this.select()" name="new_name" />
<button type="submit" />Créer un Libreto</button>
<button type="submit" /><?= localize("create-libreto") ?></button>
</form>
</div>
</article>

View file

@ -7,6 +7,7 @@ require_once './assets/parsedown-extra/ParsedownExtra.php';
require_once './assets/html2opendocument/Base.php';
require_once './assets/html2opendocument/Text.php';
require_once './assets/htmlpurifier/library/HTMLPurifier.auto.php';
require_once './assets/spyc/Spyc.php';
$Purifier = new HTMLPurifier();
$Parsedown = new ParsedownExtra();
@ -161,13 +162,31 @@ function get_libreto_name() {
return $name;
}
function curl_get_contents($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
function get_user_language() {
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($lang){
case "fr":
return "fr";
break;
default:
return "en";
break;
}
}
function load_translation_file() {
return spyc_load_file("assets/texts/translation.yml");
}
function localize($key) {
global $translation, $user_language;
if (array_key_exists($key, $translation)) :
if (array_key_exists($user_language, $translation[$key])) :
return $translation[$key][$user_language];
elseif (array_key_exists($fallback_language, $translation[$key])) :
return $translation[$key][$fallback_language];
endif;
else:
return "$key ($user_language)";
endif;
}

View file

@ -20,6 +20,8 @@ if(isset($_GET['mode'])):
endif;
$user_language = get_user_language();
$translation = load_translation_file();
$custom_css = false;
$libreto_name = get_libreto_name();
$pads_list = get_pads_list();