add localization and move timezone selection to the right place

This commit is contained in:
coderkun 2014-01-19 23:03:55 +01:00
commit da7cda02f9
15 changed files with 141 additions and 13 deletions

View file

@ -17,12 +17,21 @@
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
class HtmlAgent extends \nre\agents\ToplevelAgent
class HtmlAgent extends \hhu\z\ToplevelAgent
{
protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
{
parent::__construct($request, $response, $log);
$this->setLanguage($request);
}
/**
* Action: index.
*/
@ -32,6 +41,27 @@
$this->addSubAgent('Menu');
}
private function setLanguage(\nre\core\Request $request)
{
// Set domain
$domain = \nre\configs\AppConfig::$app['name'];
// Get language
$locale = $request->getGetParam('lang', 'language');
if(is_null($locale)) {
return;
}
// Load translation
putenv("LC_ALL=$locale");
setlocale(LC_ALL, $locale);
bindtextdomain($domain, ROOT.DS.\nre\configs\AppConfig::$dirs['locale']);
textdomain($domain);
}
}
?>

View file

@ -44,9 +44,6 @@
public function __construct($layoutName, $action, $agent)
{
parent::__construct($layoutName, $action, $agent);
// Set timezone
date_default_timezone_set(\nre\configs\AppConfig::$app['timeZone']);
}

36
app/ToplevelAgent.inc Normal file
View file

@ -0,0 +1,36 @@
<?php
/**
* The Legend of Z
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
* @copyright 2014 Heinrich-Heine-Universität Düsseldorf
* @license http://www.gnu.org/licenses/gpl.html
* @link https://bitbucket.org/coderkun/the-legend-of-z
*/
namespace hhu\z;
/**
* Abstract class for implementing an application Controller.
*
* @author Oliver Hanraths <oliver.hanraths@uni-duesseldorf.de>
*/
abstract class ToplevelAgent extends \nre\agents\ToplevelAgent
{
protected function __construct(\nre\core\Request $request, \nre\core\Response $response, \nre\core\Logger $log=null)
{
parent::__construct($request, $response, $log);
// Set timezone
date_default_timezone_set(\nre\configs\AppConfig::$app['timeZone']);
}
}
?>

View file

@ -30,6 +30,7 @@
* @var array
*/
public static $app = array(
'name' => 'The Legend of Z',
'namespace' => 'hhu\\z\\',
'timeZone' => 'Europe/Berlin'
);
@ -45,7 +46,19 @@
'toplevel' => 'html',
'toplevel-error' => 'fault',
'intermediate' => 'introduction',
'intermediate-error' => 'error'
'intermediate-error' => 'error',
'language' => 'de_DE.utf8'
);
/**
* Directories
*
* @static
* @var array
*/
public static $dirs = array(
'locale' => 'locale'
);

View file

@ -65,6 +65,9 @@
// Get seminary
$seminary = $this->Seminaries->getSeminaryByUrl($seminaryUrl);
// Created user
$seminary['creator'] = $this->Users->getUserById($seminary['created_user_id']);
// Pass data to view
$this->set('seminary', $seminary);

Binary file not shown.

View file

@ -0,0 +1,45 @@
msgid ""
msgstr ""
"Project-Id-Version: The Legend of Z\n"
"POT-Creation-Date: 2014-01-19 22:56+0100\n"
"PO-Revision-Date: 2014-01-19 22:58+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.6.3\n"
"X-Poedit-Basepath: .\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"
"X-Poedit-SearchPath-0: ../../../views\n"
#: ../../../views/html/menu/index.tpl:2 ../../../views/html/users/user.tpl:1
#: ../../../views/html/users/index.tpl:1
msgid "Users"
msgstr "Benutzer"
#: ../../../views/html/menu/index.tpl:3
#: ../../../views/html/seminaries/seminary.tpl:1
#: ../../../views/html/seminaries/index.tpl:1
msgid "Seminaries"
msgstr "Kurse"
#: ../../../views/html/users/user.tpl:4 ../../../views/html/users/index.tpl:7
msgid "registered on"
msgstr "registriert seit"
#: ../../../views/html/error/index.tpl:1
msgid "Error"
msgstr "Fehler"
#: ../../../views/html/seminaries/seminary.tpl:4
#: ../../../views/html/seminaries/index.tpl:7
#, php-format
msgid "created by %s on %s"
msgstr "erstellt von %s am %s"
#: ../../../views/html/introduction/index.tpl:1
msgid "Introduction"
msgstr "Einführung"

View file

@ -1,2 +1,2 @@
<h1>Fehler</h1>
<h1><?=_('Error')?></h1>
<p class="error"><?=$code?>: <?=$string?></p>

View file

@ -16,7 +16,6 @@
</nav>
</header>
<article>
<h1><?=$title?></h1>
<?=$intermediate?>
</article>
</body>

View file

@ -1,3 +1,4 @@
<h1><?=_('Introduction')?></h1>
<p>Ein Projekt zum Thema „Gamification im Lehrumfeld“ basierend auf <a href="http://legende-von-zyren.de">Die Legende von Zyren</a>.</p>
<p>Entwickler:</p>
<ul>

View file

@ -1,4 +1,4 @@
<menu>
<li><a href="<?=$linker->link("users")?>">Users</a></li>
<li><a href="<?=$linker->link("seminaries")?>">Seminaries</a></li>
<li><a href="<?=$linker->link("users")?>"><?=_('Users')?></a></li>
<li><a href="<?=$linker->link("seminaries")?>"><?=_('Seminaries')?></a></li>
</menu>

View file

@ -1,9 +1,10 @@
<h1><?=_('Seminaries')?></h1>
<ul>
<?php foreach($seminaries as &$seminary) : ?>
<li>
<h2><a href="<?=$linker->link(array('seminary', $seminary['url']), 1)?>"><?=$seminary['title']?></a></h2>
<details>
<summary>erstellt von <?=$seminary['creator']['username']?></summary>
<summary><?=sprintf(_('created by %s on %s'), $seminary['creator']['username'], date(\hhu\z\Utils::DATEFORMAT, strtotime($seminary['created'])))?></summary>
</details>
</li>
<?php endforeach ?>

View file

@ -1,4 +1,5 @@
<h1><?=_('Seminaries')?></h1>
<h2><?=$seminary['title']?></h2>
<p>
erstellt am <?=date(\hhu\z\Utils::DATEFORMAT, strtotime($seminary['created']))?>
<?=sprintf(_('created by %s on %s'), $seminary['creator']['username'], date(\hhu\z\Utils::DATEFORMAT, strtotime($seminary['created'])))?>
</p>

View file

@ -1,9 +1,10 @@
<h1><?=_('Users')?></h1>
<ul>
<?php foreach($users as &$user) : ?>
<li>
<h2><a href="<?=$linker->link(array('user', $user['username']), 1)?>"><?=$user['username']?></a></h2>
<details>
<summary>registriert seit <?=date(\hhu\z\Utils::DATEFORMAT, strtotime($user['created']))?></summary>
<summary><?=_('registered on')?> <?=date(\hhu\z\Utils::DATEFORMAT, strtotime($user['created']))?></summary>
</details>
</li>
<?php endforeach ?>

View file

@ -1,4 +1,5 @@
<h1><?=_('Users')?></h1>
<h2><?=$user['username']?></h2>
<p>
registriert seit <?=date(\hhu\z\Utils::DATEFORMAT, strtotime($user['created']))?>
<?=_('registered on')?> <?=date(\hhu\z\Utils::DATEFORMAT, strtotime($user['created']))?>
</p>