diff --git a/sources/config.php b/sources/config.php index ee0b220..c767de2 100644 --- a/sources/config.php +++ b/sources/config.php @@ -1,8 +1,8 @@ - * Contribute at https://github.com/jvaubourg/vpnclient_ynh + * Contribute at https://github.com/jvaubourg/hotspot_ynh * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by @@ -18,57 +18,56 @@ * along with this program. If not, see . */ -// Limonade configuration +// Framework configuration function configure() { - option('env', ENV_PRODUCTION); - option('debug', false); - option('base_uri', '/'); - layout("layout.html.php"); - define('PUBLIC_DIR', '/public'); -} + option('env', ENV_PRODUCTION); + option('debug', false); + option('base_uri', '/'); -// Not found page -function not_found($errno, $errstr, $errfile=null, $errline=null) { - $msg = h(rawurldecode($errstr)); - return render($msg, 'error_layout.html.php'); -} + layout('layout.html.php'); -function T_($string) { - return gettext($string); + define('PUBLIC_DIR', '/public'); } // Before routing function before($route) { - /** - * * Locale - * */ - if (!isset($_SESSION['locale'])) { - $locale = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']); - $_SESSION['locale'] = strtolower(substr(chop($locale[0]),0,2)); - } - $textdomain="localization"; - putenv('LANGUAGE='.$_SESSION['locale']); - putenv('LANG='.$_SESSION['locale']); - putenv('LC_ALL='.$_SESSION['locale']); - putenv('LC_MESSAGES='.$_SESSION['locale']); - setlocale(LC_ALL,$_SESSION['locale']); - setlocale(LC_CTYPE,$_SESSION['locale']); - $locales_dir = dirname(__FILE__).'/../i18n'; - bindtextdomain($textdomain,$locales_dir); - bind_textdomain_codeset($textdomain, 'UTF-8'); - textdomain($textdomain); - // Set the $locale variable in template - set('locale', $_SESSION['locale']); + $lang_mapping = array( + 'fr' => 'fr_FR' + ); + + if(!isset($_SESSION['locale'])) { + $locale = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); + $_SESSION['locale'] = strtolower(substr(chop($locale[0]), 0, 2)); + } + + $lang = $_SESSION['locale']; + + // Convert simple language code into full language code + if(array_key_exists($lang, $lang_mapping)) { + $lang = $lang_mapping[$lang]; + } + + $lang = "$lang.utf8"; + $textdomain = "localization"; + + putenv("LANGUAGE=$lang"); + putenv("LANG=$lang"); + putenv("LC_ALL=$lang"); + putenv("LC_MESSAGES=$lang"); + + setlocale(LC_ALL, $lang); + setlocale(LC_CTYPE, $lang); + + $locales_dir = dirname(__FILE__).'/i18n'; + + bindtextdomain($textdomain, $locales_dir); + bind_textdomain_codeset($textdomain, 'UTF-8'); + textdomain($textdomain); + + set('locale', $lang); } // After routing function after($output, $route) { - /* - $time = number_format( (float)substr(microtime(), 0, 10) - LIM_START_MICROTIME, 6); - $output .= "\n\n"; - $output .= ""; - */ - return $output; + return $output; } diff --git a/sources/controller.php b/sources/controller.php index 1c26179..b8e0d47 100644 --- a/sources/controller.php +++ b/sources/controller.php @@ -93,40 +93,40 @@ dispatch_put('/settings', function() { if($service_enabled == 1) { try { if(empty($_POST['server_name']) || empty($_POST['server_port']) || empty($_POST['server_proto'])) { - throw new Exception(T_('The Server Address, the Server Port and the Protocol cannot be empty')); + throw new Exception(_('The Server Address, the Server Port and the Protocol cannot be empty')); } if(!preg_match('/^\d+$/', $_POST['server_port'])) { - throw new Exception(T_('The Server Port must be only composed of digits')); + throw new Exception(_('The Server Port must be only composed of digits')); } if($_POST['server_proto'] != 'udp' && $_POST['server_proto'] != 'tcp') { - throw new Exception(T_('The Protocol must be "udp" or "tcp"')); + throw new Exception(_('The Protocol must be "udp" or "tcp"')); } if(($_FILES['crt_client']['error'] == UPLOAD_ERR_OK && $_FILES['crt_client_key']['error'] != UPLOAD_ERR_OK && (!$crt_client_key_exists || $_POST['crt_client_key_delete'] == 1)) || ($_FILES['crt_client_key']['error'] == UPLOAD_ERR_OK && $_FILES['crt_client']['error'] != UPLOAD_ERR_OK && (!$crt_client_exists || $_POST['crt_client_delete'] == 1))) { - throw new Exception(T_('A Client Certificate is needed when you suggest a Key, or vice versa')); + throw new Exception(_('A Client Certificate is needed when you suggest a Key, or vice versa')); } if(empty($_POST['login_user']) xor empty($_POST['login_passphrase'])) { - throw new Exception(T_('A Password is needed when you suggest a Username, or vice versa')); + throw new Exception(_('A Password is needed when you suggest a Username, or vice versa')); } if($_FILES['crt_server_ca']['error'] != UPLOAD_ERR_OK && !$crt_server_ca_exists) { - throw new Exception(T_('You need a Server CA.')); + throw new Exception(_('You need a Server CA.')); } if(($_FILES['crt_client_key']['error'] != UPLOAD_ERR_OK && (!$crt_client_key_exists || $_POST['crt_client_key_delete'] == 1)) && empty($_POST['login_user'])) { - throw new Exception(T_('You need either a Client Certificate, either a Username, or both')); + throw new Exception(_('You need either a Client Certificate, either a Username, or both')); } if($ip6_net != 'none') { $ip6_net = ipv6_expanded($ip6_net); if(empty($ip6_net)) { - throw new Exception(T_('The IPv6 Delegated Prefix format looks bad')); + throw new Exception(_('The IPv6 Delegated Prefix format looks bad')); } $ip6_blocs = explode(':', $ip6_net); @@ -137,7 +137,7 @@ dispatch_put('/settings', function() { } } catch(Exception $e) { - flash('error', $e->getMessage().' ('.T_('configuration not updated').').'); + flash('error', $e->getMessage().' ('._('configuration not updated').').'); goto redirect; } } @@ -182,13 +182,13 @@ dispatch_put('/settings', function() { $retcode = start_service(); if($retcode == 0) { - flash('success', T_('Configuration updated and service successfully reloaded')); + flash('success', _('Configuration updated and service successfully reloaded')); } else { - flash('error', T_('Configuration updated but service reload failed')); + flash('error', _('Configuration updated but service reload failed')); } } else { - flash('success', T_('Service successfully disabled')); + flash('success', _('Service successfully disabled')); } redirect: diff --git a/sources/i18n/README b/sources/i18n/README deleted file mode 100644 index a6462b7..0000000 --- a/sources/i18n/README +++ /dev/null @@ -1,3 +0,0 @@ -Add a "localization.pot" to this directory, and one folder per translated language, containing the po a LC_MESSAGE directory (with the .mo) - -See: https://github.com/YunoHost/admin_v1/tree/master/i18n diff --git a/sources/i18n/README.md b/sources/i18n/README.md new file mode 100644 index 0000000..d3e69f1 --- /dev/null +++ b/sources/i18n/README.md @@ -0,0 +1,45 @@ +## Force language + +The default language of the web admin depends on your browser language. + +You can force a language by using (e.g. for French): +``` +/vpnadmin/?/lang/fr +``` + +English is the default language when the browser language is not available. + +## Update the default string list + +Updating the pot file from template files: +``` +xgettext sources/views/* -o sources/i18n/localization.pot +``` + +## Add a new language + +Create a new directory path (e.g. for French): +``` +mkdir -p sources/i18n/fr_FR/LC_MESSAGES/ +``` + +Generate the po file: +``` +msginit --locale=fr_FR.UTF-8 --no-translator -i sources/i18n/localization.pot -o sources/i18n/fr_FR/LC_MESSAGES/localization.po +``` + +You can use poedit for translating the po: +``` +poedit sources/i18n/fr_FR/LC_MESSAGES/localization.po +``` + +With poedit, just save your modifications with the button and the *localization.mo* (compiled version of the po) file will automatically be created or updated. + +If you edited the po by hand, you have to compile the mo file: +``` +msgfmt sources/i18n/fr_FR/localization.po -o sources/i18n/fr_FR/LC_MESSAGES/localization.mo +``` + +Change the default language of your browser, and test this new translation. + +You should add the locale to the list at the end of *sources/controller.php*. diff --git a/sources/i18n/fr_FR/LC_MESSAGES/localization.po b/sources/i18n/fr_FR/LC_MESSAGES/localization.po new file mode 100644 index 0000000..efa53ab --- /dev/null +++ b/sources/i18n/fr_FR/LC_MESSAGES/localization.po @@ -0,0 +1,207 @@ +# French translations for PACKAGE package. +# Copyright (C) 2015 THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# Automatically generated, 2015. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-07-08 19:18+0200\n" +"PO-Revision-Date: 2015-07-08 19:18+0200\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=ASCII\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#: sources/views/layout.html.php:27 +msgid "VPN Client" +msgstr "" + +#: sources/views/layout.html.php:49 +msgid "Error" +msgstr "" + +#: sources/views/layout.html.php:54 sources/views/settings.html.php:125 +#: sources/views/settings.html.php:165 +msgid "Notice" +msgstr "" + +#: sources/views/layout.html.php:66 +msgid "Any problem? Contribute!" +msgstr "" + +#: sources/views/settings.html.php:20 +msgid "VPN Client Configuration" +msgstr "" + +#: sources/views/settings.html.php:22 sources/views/settings.html.php:24 +msgid "" +"This is a fast status. Click on More details to show the complete status." +msgstr "" + +#: sources/views/settings.html.php:22 +msgid "Running" +msgstr "" + +#: sources/views/settings.html.php:24 +msgid "Not Running" +msgstr "" + +#: sources/views/settings.html.php:27 +msgid "Loading complete status may take a few minutes. Be patient." +msgstr "" + +#: sources/views/settings.html.php:27 +msgid "More details" +msgstr "" + +#: sources/views/settings.html.php:43 +msgid "Service" +msgstr "" + +#: sources/views/settings.html.php:48 +msgid "VPN Enabled" +msgstr "" + +#: sources/views/settings.html.php:60 +msgid "VPN" +msgstr "" + +#: sources/views/settings.html.php:65 +msgid "Server Address" +msgstr "" + +#: sources/views/settings.html.php:72 +msgid "Server Port" +msgstr "" + +#: sources/views/settings.html.php:74 +msgid "With restricted access, you should use 443 (TCP) or 53 (UDP)" +msgstr "" + +#: sources/views/settings.html.php:79 +msgid "Protocol" +msgstr "" + +#: sources/views/settings.html.php:82 +msgid "UDP" +msgstr "" + +#: sources/views/settings.html.php:85 +msgid "" +"UDP is more efficient than TCP (but more filtered in case of restrictive " +"access)" +msgstr "" + +#: sources/views/settings.html.php:86 +msgid "TCP" +msgstr "" + +#: sources/views/settings.html.php:94 +msgid "Edit the raw configuration only if you know what you do!" +msgstr "" + +#: sources/views/settings.html.php:94 sources/views/settings.html.php:99 +msgid "Advanced" +msgstr "" + +#: sources/views/settings.html.php:109 +msgid "IPv6" +msgstr "" + +#: sources/views/settings.html.php:114 +msgid "Delegated prefix" +msgstr "" + +#: sources/views/settings.html.php:116 +msgid "" +"Leave empty if your Internet Service Provider does not give you a delegated " +"prefix" +msgstr "" + +#: sources/views/settings.html.php:125 +msgid "" +"You need to upload a Client Certificate, or define a Username (or both) for " +"starting your VPN Client." +msgstr "" + +#: sources/views/settings.html.php:131 +msgid "Certificates" +msgstr "" + +#: sources/views/settings.html.php:136 +msgid "Update Client Cert." +msgstr "" + +#: sources/views/settings.html.php:136 +msgid "Upload Client Cert." +msgstr "" + +#: sources/views/settings.html.php:139 sources/views/settings.html.php:152 +msgid "Delete this certificate" +msgstr "" + +#: sources/views/settings.html.php:144 sources/views/settings.html.php:157 +#: sources/views/settings.html.php:177 +msgid "Browse" +msgstr "" + +#: sources/views/settings.html.php:149 +msgid "Update Client Key" +msgstr "" + +#: sources/views/settings.html.php:149 +msgid "Upload Client Key" +msgstr "" + +#: sources/views/settings.html.php:155 +msgid "Make sure your browser is able to read the key file before uploading" +msgstr "" + +#: sources/views/settings.html.php:157 +msgid "make sure your browser is able to read the key file before uploading" +msgstr "" + +#: sources/views/settings.html.php:165 +msgid "You need to upload a Server CA for starting your VPN Client." +msgstr "" + +#: sources/views/settings.html.php:169 +msgid "Update Server CA" +msgstr "" + +#: sources/views/settings.html.php:169 +msgid "Upload Server CA" +msgstr "" + +#: sources/views/settings.html.php:172 +msgid "You cannot have no server CA" +msgstr "" + +#: sources/views/settings.html.php:185 +msgid "Login" +msgstr "" + +#: sources/views/settings.html.php:190 +msgid "Username" +msgstr "" + +#: sources/views/settings.html.php:192 sources/views/settings.html.php:199 +msgid "Leave empty if not necessary" +msgstr "" + +#: sources/views/settings.html.php:197 +msgid "Password" +msgstr "" + +#: sources/views/settings.html.php:207 +msgid "Reloading may take a few minutes. Be patient." +msgstr "" + +#: sources/views/settings.html.php:207 +msgid "Save and reload" +msgstr "" diff --git a/sources/i18n/localization.pot b/sources/i18n/localization.pot new file mode 100644 index 0000000..043bf00 --- /dev/null +++ b/sources/i18n/localization.pot @@ -0,0 +1,207 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-07-08 19:18+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: sources/views/layout.html.php:27 +msgid "VPN Client" +msgstr "" + +#: sources/views/layout.html.php:49 +msgid "Error" +msgstr "" + +#: sources/views/layout.html.php:54 sources/views/settings.html.php:125 +#: sources/views/settings.html.php:165 +msgid "Notice" +msgstr "" + +#: sources/views/layout.html.php:66 +msgid "Any problem? Contribute!" +msgstr "" + +#: sources/views/settings.html.php:20 +msgid "VPN Client Configuration" +msgstr "" + +#: sources/views/settings.html.php:22 sources/views/settings.html.php:24 +msgid "" +"This is a fast status. Click on More details to show the complete status." +msgstr "" + +#: sources/views/settings.html.php:22 +msgid "Running" +msgstr "" + +#: sources/views/settings.html.php:24 +msgid "Not Running" +msgstr "" + +#: sources/views/settings.html.php:27 +msgid "Loading complete status may take a few minutes. Be patient." +msgstr "" + +#: sources/views/settings.html.php:27 +msgid "More details" +msgstr "" + +#: sources/views/settings.html.php:43 +msgid "Service" +msgstr "" + +#: sources/views/settings.html.php:48 +msgid "VPN Enabled" +msgstr "" + +#: sources/views/settings.html.php:60 +msgid "VPN" +msgstr "" + +#: sources/views/settings.html.php:65 +msgid "Server Address" +msgstr "" + +#: sources/views/settings.html.php:72 +msgid "Server Port" +msgstr "" + +#: sources/views/settings.html.php:74 +msgid "With restricted access, you should use 443 (TCP) or 53 (UDP)" +msgstr "" + +#: sources/views/settings.html.php:79 +msgid "Protocol" +msgstr "" + +#: sources/views/settings.html.php:82 +msgid "UDP" +msgstr "" + +#: sources/views/settings.html.php:85 +msgid "" +"UDP is more efficient than TCP (but more filtered in case of restrictive " +"access)" +msgstr "" + +#: sources/views/settings.html.php:86 +msgid "TCP" +msgstr "" + +#: sources/views/settings.html.php:94 +msgid "Edit the raw configuration only if you know what you do!" +msgstr "" + +#: sources/views/settings.html.php:94 sources/views/settings.html.php:99 +msgid "Advanced" +msgstr "" + +#: sources/views/settings.html.php:109 +msgid "IPv6" +msgstr "" + +#: sources/views/settings.html.php:114 +msgid "Delegated prefix" +msgstr "" + +#: sources/views/settings.html.php:116 +msgid "" +"Leave empty if your Internet Service Provider does not give you a delegated " +"prefix" +msgstr "" + +#: sources/views/settings.html.php:125 +msgid "" +"You need to upload a Client Certificate, or define a Username (or both) for " +"starting your VPN Client." +msgstr "" + +#: sources/views/settings.html.php:131 +msgid "Certificates" +msgstr "" + +#: sources/views/settings.html.php:136 +msgid "Update Client Cert." +msgstr "" + +#: sources/views/settings.html.php:136 +msgid "Upload Client Cert." +msgstr "" + +#: sources/views/settings.html.php:139 sources/views/settings.html.php:152 +msgid "Delete this certificate" +msgstr "" + +#: sources/views/settings.html.php:144 sources/views/settings.html.php:157 +#: sources/views/settings.html.php:177 +msgid "Browse" +msgstr "" + +#: sources/views/settings.html.php:149 +msgid "Update Client Key" +msgstr "" + +#: sources/views/settings.html.php:149 +msgid "Upload Client Key" +msgstr "" + +#: sources/views/settings.html.php:155 +msgid "Make sure your browser is able to read the key file before uploading" +msgstr "" + +#: sources/views/settings.html.php:157 +msgid "make sure your browser is able to read the key file before uploading" +msgstr "" + +#: sources/views/settings.html.php:165 +msgid "You need to upload a Server CA for starting your VPN Client." +msgstr "" + +#: sources/views/settings.html.php:169 +msgid "Update Server CA" +msgstr "" + +#: sources/views/settings.html.php:169 +msgid "Upload Server CA" +msgstr "" + +#: sources/views/settings.html.php:172 +msgid "You cannot have no server CA" +msgstr "" + +#: sources/views/settings.html.php:185 +msgid "Login" +msgstr "" + +#: sources/views/settings.html.php:190 +msgid "Username" +msgstr "" + +#: sources/views/settings.html.php:192 sources/views/settings.html.php:199 +msgid "Leave empty if not necessary" +msgstr "" + +#: sources/views/settings.html.php:197 +msgid "Password" +msgstr "" + +#: sources/views/settings.html.php:207 +msgid "Reloading may take a few minutes. Be patient." +msgstr "" + +#: sources/views/settings.html.php:207 +msgid "Save and reload" +msgstr "" diff --git a/sources/views/layout.html.php b/sources/views/layout.html.php index ba99543..84f0815 100644 --- a/sources/views/layout.html.php +++ b/sources/views/layout.html.php @@ -24,7 +24,7 @@ - <?= T_("VPN Client") ?><?= isset($title) ? " | $title" : '' ?> + <?= _("VPN Client") ?><?= isset($title) ? " | $title" : '' ?> @@ -46,12 +46,12 @@ diff --git a/sources/views/settings.html.php b/sources/views/settings.html.php index c6cd3c2..ac9dcc4 100644 --- a/sources/views/settings.html.php +++ b/sources/views/settings.html.php @@ -17,14 +17,14 @@ along with this program. If not, see . --> -

+

- + - + -   Loading... +   Loading...