Commit aefbc2e7 authored by Michael Herold's avatar Michael Herold
Browse files

Fixes #14: Message templates and german l10n

parent b8c2e0c0
......@@ -21,6 +21,7 @@ Required Debian packages
- gettext
- make
- php5 (>= 5.6)
- php5-intl
- php5-pgsql
### Installation
......
......@@ -33,9 +33,10 @@ class I10n
{
$guessedLocale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
$locales = array_filter(self::$supportedLocales
$locales = array_filter(
self::$supportedLocales
,
function ($supportedLocale) use ($guessedLocale) {
function ($supportedLocale) use ($guessedLocale) {
return substr($supportedLocale, 0, 2) == substr($guessedLocale, 0, 2);
}
);
......@@ -77,4 +78,15 @@ class I10n
{
return substr($this->locale, 0, 2);
}
/**
*
* @param string $pattern
* @param array $args
* @return string
*/
public function msg($pattern, array $args)
{
return \MessageFormatter::formatMessage($this->locale, $pattern, $args);
}
}
......@@ -43,6 +43,12 @@ class LoadModule
*/
protected $pdo;
/**
*
* @var I10n
*/
protected $i10n;
/**
* Returns true if the given string is a valid module name. Module names
* must start with a lowercase letter and continue with at least one other
......@@ -70,10 +76,12 @@ class LoadModule
*
* @param string $moduleId
*/
public function __construct($moduleId, sql\Connection $pdo = null)
public function __construct($moduleId, sql\Connection $pdo = null,
I10n $i10n = null)
{
$this->moduleId = $moduleId;
$this->pdo = $pdo;
$this->i10n = $i10n;
if (!self::validName($moduleId)) {
$msg = sprintf(
......@@ -121,7 +129,7 @@ class LoadModule
public function getInstance(Request $request)
{
$moduleClass = $this->moduleClass;
return new $moduleClass($request, $this->pdo);
return new $moduleClass($request, $this->pdo, $this->i10n);
}
public function getContent(Request $request, I10n $i10n)
......
......@@ -38,6 +38,12 @@ abstract class Module implements ModuleInterface
*/
public $pdo;
/**
*
* @var I10n
*/
public $i10n;
/**
* @return \hemio\html\Interface_\HtmlCode HTML code for module
*/
......@@ -45,10 +51,12 @@ abstract class Module implements ModuleInterface
abstract protected function constructHook();
public function __construct(Request $request, sql\Connection $pdo)
public function __construct(Request $request, sql\Connection $pdo,
I10n $i10n)
{
$this->request = $request;
$this->pdo = $pdo;
$this->i10n = $i10n;
$this->constructHook();
}
}
<?php
/*
* Copyright (C) 2015 Michael Herold <quabla@hemio.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @var \hemio\edentata\I10n
*/
$i10n = null;
function _msg($pattern, array $args)
{
global $i10n;
return \MessageFormatter::formatMessage($i10n->locale, $pattern, $args);
}
......@@ -21,6 +21,8 @@ namespace hemio\edentata;
use hemio\html;
use hemio\form;
require 'src/load/functions.php';
openlog('edentata', LOG_ODELAY, LOG_USER);
ini_set('log_errors', true);
ini_set('error_log', 'syslog');
......@@ -185,7 +187,7 @@ try {
, _('User Settings')
);
$userModule = (new LoadModule('user', $pdo))->getInstance($request);
$userModule = (new LoadModule('user', $pdo, $i10n))->getInstance($request);
$users = $userModule->db->selectDeputy()->fetchAll();
if (!empty($users)) {
......@@ -249,7 +251,7 @@ try {
$mainContent->addChild($nav);
foreach ($config['modules_settings'] as $moduleId) {
$loadedModule = new LoadModule($moduleId, $pdo);
$loadedModule = new LoadModule($moduleId, $pdo, $i10n);
$a = $list->addLinkEntry(
$request->deriveModule($moduleId)
......@@ -260,7 +262,7 @@ try {
$a->addCssClass('selected');
}
$loadedModule = new LoadModule($activeModuleName, $pdo);
$loadedModule = new LoadModule($activeModuleName, $pdo, $i10n);
$content = $loadedModule->getContent($request, $i10n);
$mainContent->addChild($content);
......@@ -268,7 +270,7 @@ try {
if (!in_array($activeModuleName, $modulesAllowed))
throw new exception\Error(_('Tried to access unknown or disabled module'));
$loadedModule = new LoadModule($activeModuleName, $pdo);
$loadedModule = new LoadModule($activeModuleName, $pdo, $i10n);
$title->setValue(sprintf($config['title'], $loadedModule->getName()));
......
......@@ -30,8 +30,9 @@ class RegisteredDelete extends Window
public function content($domain)
{
$message = sprintf(_('Irrevokably delete the registered domain "%s". '
.'This operation cannot be made undone.'), $domain);
$message = _msg(_('Are you sure you want to irrevokably delete the registered domain "{domain}"? '
.'This operation cannot be made undone.')
, ['domain' => $domain]);
$window = $this->newDeleteWindow(
'registered_delete'
......
msgid ""
msgstr ""
"Project-Id-Version: edentata dns\n"
"POT-Creation-Date: 2015-08-03 15:27+0100\n"
"PO-Revision-Date: 2015-08-03 15:33+0100\n"
"POT-Creation-Date: 2015-08-05 18:24+0100\n"
"PO-Revision-Date: 2015-08-05 18:25+0100\n"
"Last-Translator: Michael Herold <quabla@hemio.de>\n"
"Language-Team: \n"
"Language: de_DE\n"
......@@ -200,7 +200,7 @@ msgstr "Handle Löschen"
#: HandleDelete.php:37
msgid "Are you sure you want to delete this handle?"
msgstr ""
msgstr "Sind Sie sicher, dass Sie dieses Handle löschen möchten?"
#: HandleDetails.php:35
msgid "Handle"
......@@ -210,7 +210,7 @@ msgstr ""
msgid "ID"
msgstr ""
#: Module.php:159 RegisteredCreate.php:41 RegisteredDetails.php:35
#: Module.php:163 RegisteredCreate.php:41 RegisteredDetails.php:35
msgid "Domain"
msgstr ""
......@@ -263,13 +263,15 @@ msgid "Registrant (Owner)"
msgstr "Besitzer (Owner)"
#: RegisteredDelete.php:33
#, php-format
msgid ""
"Irrevokably delete the registered domain \"%s\". This operation cannot be "
"made undone."
msgstr "Möchten Sie die registrierte Domain \"%s\" unwiderruflich löschen?"
"Are you sure you want to irrevokably delete the registered domain "
"\"{domain}\"? This operation cannot be made undone."
msgstr ""
"Sind Sie sicher, dass Sie die registrierte Domain \"{domain}\" "
"unwiderruflich löschen möchten? Dieser Vorgang kann nicht rückgängig gemacht "
"werden."
#: RegisteredDelete.php:38 RegisteredDelete.php:41
#: RegisteredDelete.php:39 RegisteredDelete.php:42
msgid "Delete Registered Domain"
msgstr "Registrierte Domain Löschen"
......
......@@ -30,16 +30,17 @@ class AliasDelete extends Window
public function content($mailbox, $alias)
{
$message = _(
'Do you really want to delete the alias "%1$s"? After'.
' deleting the alias you will no longer be reachable via "%1$s".'
$message = _msg(_(
'Are you sure you want to permanently delete the alias "{alias}"? After'.
' deleting the alias you will no longer be reachable via "{alias}".')
, ['alias' => $alias]
);
$window = $this->newDeleteWindow(
'alias_delete'
, _('Delete Alias')
, $alias
, sprintf($message, $alias)
, $message
, _('Delete Alias')
);
......
<?php
/*
* Copyright (C) 2015 Michael Herold <quabla@hemio.de>
*
......@@ -27,23 +26,26 @@ use hemio\edentata\exception;
*
* @author Michael Herold <quabla@hemio.de>
*/
class MailboxDelete extends Window {
class MailboxDelete extends Window
{
public function content($address) {
$msg = _(
public function content($address)
{
$msg = _msg(
_(
'Are you sure you want to permanently delete the'
. ' mailbox "%1$s"? If you delete a mailbox, all stored '
. ' emails will be permanently lost and you will no'
. ' longer be reachable via "%1$s".'
);
.' mailbox "{address}"? If you delete a mailbox, all stored '
.' emails will be permanently lost and you will no'
.' longer be reachable via "{address}".'
), ['address' => $address]);
$window = $this->newDeleteWindow(
'mailbox_delete'
, 'Delete Mailbox'
, $address
, sprintf($msg, $address)
, _('Delete Mailbox')
, true
'mailbox_delete'
, _('Delete Mailbox')
, $address
, $msg
, _('Delete Mailbox')
, true
);
$this->handleSubmit($window->getForm(), $address);
......@@ -51,7 +53,8 @@ class MailboxDelete extends Window {
return $window;
}
protected function handleSubmit(gui\FormPost $form, $address) {
protected function handleSubmit(gui\FormPost $form, $address)
{
if ($form->submitted()) {
if ($form->dataValid()) {
......@@ -63,5 +66,4 @@ class MailboxDelete extends Window {
}
}
}
}
<?php
/*
* Copyright (C) 2015 Michael Herold <quabla@hemio.de>
*
......@@ -18,38 +17,44 @@
*/
namespace hemio\edentata\module\email;
use hemio\edentata\gui;
/**
* Description of RedirectionDelete
*
* @author Michael Herold <quabla@hemio.de>
*/
class RedirectionDelete extends Window {
class RedirectionDelete extends Window
{
public function content($redirection) {
$message = _('Do you really want to delete this redirection?');
public function content($redirection)
{
$message = _msg(_('Are you sure you want to permanently delete the redirection "{address}"?'
.'After deleting the redirection you will no longer be reachable via "{address}".')
, ['address' => $redirection]);
$window = $this->newDeleteWindow(
'redirection_delete'
, _('Delete Redirection')
, $redirection
, $message
, _('Delete Redirection')
'redirection_delete'
, _('Delete Redirection')
, $redirection
, $message
, _('Delete Redirection')
);
$this->handleSubmit($window->getForm(), $redirection);
return $window;
}
public function handleSubmit(gui\FormPost $form, $redirection ) {
public function handleSubmit(gui\FormPost $form, $redirection)
{
if ($form->correctSubmitted()) {
$params = Db::emailAddressToArgs($redirection);
$this->db->redirectionDelete($params);
throw new \hemio\edentata\exception\Successful;
}
}
}
msgid ""
msgstr ""
"Project-Id-Version: edentata email\n"
"POT-Creation-Date: 2015-04-28 00:51+0100\n"
"PO-Revision-Date: 2015-04-28 00:51+0100\n"
"POT-Creation-Date: 2015-08-05 17:58+0100\n"
"PO-Revision-Date: 2015-08-05 18:11+0100\n"
"Last-Translator: Michael Herold <quabla@hemio.de>\n"
"Language-Team: \n"
"Language: de_DE\n"
......@@ -55,13 +55,15 @@ msgid "Mailbox"
msgstr "Postfach"
#: AliasDelete.php:34
#, php-format
msgid ""
"Do you really want to delete the alias \"%1$s\"? After deleting the alias "
"you will no longer be reachable via \"%1$s\"."
"Are you sure you want to permanently delete the alias \"{alias}\"? After "
"deleting the alias you will no longer be reachable via \"{alias}\"."
msgstr ""
"Sind Sie sicher, dass Sie das Alias \"{alias}\" dauerhaft löschen wollen? "
"Nach dem das Alias gelöscht wurde, werden Sie nicht mehr über \"{alias}\" "
"erreichbar sein."
#: AliasDelete.php:40 AliasDelete.php:43
#: AliasDelete.php:41 AliasDelete.php:44
msgid "Delete Alias"
msgstr "Alias Löschen"
......@@ -73,43 +75,50 @@ msgstr "Die gewählte E-Mail-Adresse wird bereits verwendet."
msgid "Password"
msgstr "Passwort"
#: MailboxDelete.php:34
#, php-format
#: MailboxDelete.php:36
msgid ""
"Are you sure you want to permanently delete the mailbox \"%1$s\"? If you "
"delete a mailbox, all stored emails will be permanently lost and you will "
"no longer be reachable via \"%1$s\"."
"Are you sure you want to permanently delete the mailbox \"{address}\"? If "
"you delete a mailbox, all stored emails will be permanently lost and you "
"will no longer be reachable via \"{address}\"."
msgstr ""
"Sind Sie sicher, dass Sie das Postfach \"{address}\" dauerhaft löschen "
"wollen? Nach dem das Postfach gelöscht wurde, werden alle gespeicherten "
"Nachrichten gelöscht und Sie werden nicht mehr über \"{address}\" erreichbar "
"sein."
#: MailboxDelete.php:45
#: MailboxDelete.php:47
msgid "Delete Mailbox"
msgstr "Postfach Löschen"
#: MailboxDetails.php:36
#: MailboxDetails.php:38
msgid "Email Mailbox"
msgstr "E-Mail Postfach"
#: MailboxDetails.php:57 Overview.php:117
#: MailboxDetails.php:44
msgid "Mailbox does not exist."
msgstr "Das Postfach existiert nicht."
#: MailboxDetails.php:62
msgid "Quota"
msgstr "Kontingent"
#: MailboxDetails.php:86 Overview.php:117
msgid "Delete"
msgstr "Löschen"
#: MailboxDetails.php:70
#: MailboxDetails.php:99
msgid "Aliases"
msgstr ""
msgstr "Aliasse"
#: MailboxDetails.php:80
msgid "Possible Actions"
msgstr "Mögliche Aktionen"
#: MailboxDetails.php:84
#: MailboxDetails.php:109
msgid "Change password"
msgstr "Passwort ändern"
#: MailboxDetails.php:89
#: MailboxDetails.php:114
msgid "Create alias for this mailbox"
msgstr "Alias für dieses Postfach erstellen"
#: MailboxDetails.php:94
#: MailboxDetails.php:119
msgid "Delete entire mailbox"
msgstr "Gesamtes Postfach löschen"
......@@ -157,10 +166,19 @@ msgstr "Umleitung nach"
msgid "Email Address"
msgstr "E-Mail-Adresse"
#: RedirectionDelete.php:30
msgid "Do you really want to delete this redirection?"
#: RedirectionDelete.php:33
msgid ""
"Are you sure you want to permanently delete the redirection \"{address}\"?"
"After deleting the redirection you will no longer be reachable via "
"\"{address}\"."
msgstr ""
"Sind Sie sicher, dass Sie die Umleitung \"{address}\" dauerhaft löschen "
"wollen? Nach dem die Umleitung gelöscht wurde, werden Sie nicht mehr über "
"\"{address}\" erreichbar sein."
#: RedirectionDelete.php:34 RedirectionDelete.php:37
#: RedirectionDelete.php:39 RedirectionDelete.php:42
msgid "Delete Redirection"
msgstr "Umleitung Löschen"
#~ msgid "Possible Actions"
#~ msgstr "Mögliche Aktionen"
<?php
/*
* Copyright (C) 2015 Michael Herold <quabla@hemio.de>
*
......@@ -27,18 +26,21 @@ use hemio\edentata\module\email;
*
* @author Michael Herold <quabla@hemio.de>
*/
class ListDelete extends Window {
class ListDelete extends Window
{
public function content($list) {
$message = _('Do you really want to delete this list?');
public function content($list)
{
$message = _msg(_('Are you sure you want to permanently delete the list "{address}"?')
, ['address' => $list]);
$window = $this->newDeleteWindow(
'list_delete'
, _('Delete List')
, $list
, $message
, _('Delete List')
, true
'list_delete'
, _('Delete List')
, $list
, $message
, _('Delete List')
, true
);
$this->handleSubmit($window->getForm(), $list);
......@@ -46,7 +48,8 @@ class ListDelete extends Window {
return $window;
}
protected function handleSubmit(gui\FormPost $form, $list) {
protected function handleSubmit(gui\FormPost $form, $list)
{
if ($form->correctSubmitted()) {
$params = email\Db::emailAddressToArgs($list);
......@@ -55,5 +58,4 @@ class ListDelete extends Window {
throw new \hemio\edentata\exception\Successful;
}
}
}
msgid ""
msgstr ""
"Project-Id-Version: edentata email lists\n"
"POT-Creation-Date: 2015-04-28 00:51+0100\n"
"PO-Revision-Date: 2015-04-28 00:51+0100\n"
"POT-Creation-Date: 2015-08-05 18:10+0100\n"
"PO-Revision-Date: 2015-08-05 18:14+0100\n"
"Last-Translator: Michael Herold <quabla@hemio.de>\n"
"Language-Team: \n"
"Language: de_DE\n"
......@@ -15,55 +15,63 @@ msgstr ""
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: .\n"
#: ListCreate.php:35
#: ListCreate.php:36
msgid "New Mailing List"
msgstr "Neue Mailingliste"
#: ListCreate.php:37
#: ListCreate.php:38
msgid "Create"
msgstr "Erstellen"
#: ListCreate.php:41 ListUpdate.php:43
#: ListCreate.php:42 ListDetails.php:55 ListUpdate.php:43
msgid "List Owner"
msgstr "Listeninhaber"
#: ListCreate.php:47
msgid "The address of the list owner is used for unsubscriber requests."
#: ListCreate.php:48
msgid "The address of the list owner is used for unsubscribe requests."
msgstr ""
"Die Adresse des Listeninhaber wir zur Information über unzustellbare E-Mails "
"genutzt."
#: ListDelete.php:33
msgid "Do you really want to delete this list?"
#: ListDelete.php:34
msgid "Are you sure you want to permanently delete the list \"{address}\"?"
msgstr ""
"Sind Sie sicher, dass Sie die Mailingliste \"{address}\" dauerhaft löschen "
"wollen?"
#: ListDelete.php:37 ListDelete.php:40
#: ListDelete.php:39 ListDelete.php:42
msgid "Delete List"
msgstr "Liste Löschen"
#: ListDetails.php:34 ListDetails.php:52 ListUpdate.php:38
#: ListDetails.php:37 ListUpdate.php:38
msgid "Email List"
msgstr "Mailingliste"
#: ListDetails.php:40 SubscriberCreate.php:36
#: ListDetails.php:46 SubscriberCreate.php:36
msgid "Add Subscriber"
msgstr "Neuer Abonnent"
#: ListDetails.php:56
#: ListDetails.php:52
msgid "Email list does not exist."
msgstr "Mailingliste existiert nicht."
#: ListDetails.php:66
msgid "Change list owner"
msgstr "Listeninhaber ändern"