From 379328434bb59b154a72f8b76d8368ff638876a3 Mon Sep 17 00:00:00 2001 From: coderkun Date: Sun, 19 Jan 2014 23:03:55 +0100 Subject: [PATCH] add localization and move timezone selection to the right place --- agents/toplevel/HtmlAgent.inc | 32 +++++++++++++- app/Controller.inc | 3 -- app/ToplevelAgent.inc | 36 ++++++++++++++++ configs/AppConfig.inc | 15 ++++++- controllers/SeminariesController.inc | 3 ++ locale/de_DE/LC_MESSAGES/The Legend of Z.mo | Bin 0 -> 744 bytes locale/de_DE/LC_MESSAGES/The Legend of Z.po | 45 ++++++++++++++++++++ views/html/error/index.tpl | 2 +- views/html/html.tpl | 1 - views/html/introduction/index.tpl | 1 + views/html/menu/index.tpl | 4 +- views/html/seminaries/index.tpl | 3 +- views/html/seminaries/seminary.tpl | 3 +- views/html/users/index.tpl | 3 +- views/html/users/user.tpl | 3 +- 15 files changed, 141 insertions(+), 13 deletions(-) create mode 100644 app/ToplevelAgent.inc create mode 100644 locale/de_DE/LC_MESSAGES/The Legend of Z.mo create mode 100644 locale/de_DE/LC_MESSAGES/The Legend of Z.po diff --git a/agents/toplevel/HtmlAgent.inc b/agents/toplevel/HtmlAgent.inc index e131fdf2..63ed4525 100644 --- a/agents/toplevel/HtmlAgent.inc +++ b/agents/toplevel/HtmlAgent.inc @@ -17,12 +17,21 @@ * * @author Oliver Hanraths */ - 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); + } + } ?> diff --git a/app/Controller.inc b/app/Controller.inc index 55509fbb..4403407b 100644 --- a/app/Controller.inc +++ b/app/Controller.inc @@ -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']); } diff --git a/app/ToplevelAgent.inc b/app/ToplevelAgent.inc new file mode 100644 index 00000000..97aea57b --- /dev/null +++ b/app/ToplevelAgent.inc @@ -0,0 +1,36 @@ + + * @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 + */ + 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']); + } + } + +?> diff --git a/configs/AppConfig.inc b/configs/AppConfig.inc index 8f5ab347..3467c3be 100644 --- a/configs/AppConfig.inc +++ b/configs/AppConfig.inc @@ -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' ); diff --git a/controllers/SeminariesController.inc b/controllers/SeminariesController.inc index 85867cbb..4f026f41 100644 --- a/controllers/SeminariesController.inc +++ b/controllers/SeminariesController.inc @@ -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); diff --git a/locale/de_DE/LC_MESSAGES/The Legend of Z.mo b/locale/de_DE/LC_MESSAGES/The Legend of Z.mo new file mode 100644 index 0000000000000000000000000000000000000000..ec51389a69bdbf4ffb9b427614d53912f88b5c08 GIT binary patch literal 744 zcmZvaPm9w)7{*6k{}2^K@wSKYASg23r0UX5>1DgE6uVe#R>X_UCU29Gbf(Nqs_SR) z>e-tgz|#tXh*$4>((m9W&?gOA55DA=Xa2nJGjEvuxVrI{A=_s}~31M~v)7O+KD_=IS)>t;u-kPjRy)v3jX|A-iiX1y|WF1Q_NlzI+JmNPUHyUqdDOb*u z#WG4J*1Vw9i%}+?paL#2PYU8=%1I+*#-9a~M~UdyPS_QDFpPOSjP8jr644HCx8wWU zcfu$PktiP1Qq?a1&+9aKW9hs|tkkZQ-q@H2W2y5><|Go5^MB?s&*=HyAlM)657rGv ztuW{t?McJtXn}q_z4BX&QYzi$X(6p6-#bW#qO;DckDHMd1D%>o={)A0L*;{~;sI&0 zO&=3OnesepZMW`Xr1ZK+5%X3sDJv^WF*J7WVy+jfsq3}7yczaxX?~-}qubqe z{nS)8rGC>^%$vUcx=%^kw3xtOggBwK)jUf@FI~WfRFq`dKFehler +

:

diff --git a/views/html/html.tpl b/views/html/html.tpl index 9401a5e5..0f46493c 100644 --- a/views/html/html.tpl +++ b/views/html/html.tpl @@ -16,7 +16,6 @@
-

diff --git a/views/html/introduction/index.tpl b/views/html/introduction/index.tpl index b7633b2f..1d3fa615 100644 --- a/views/html/introduction/index.tpl +++ b/views/html/introduction/index.tpl @@ -1,3 +1,4 @@ +

Ein Projekt zum Thema „Gamification im Lehrumfeld“ – basierend auf Die Legende von Zyren.

Entwickler:

    diff --git a/views/html/menu/index.tpl b/views/html/menu/index.tpl index d7c91883..ad0fbe39 100644 --- a/views/html/menu/index.tpl +++ b/views/html/menu/index.tpl @@ -1,4 +1,4 @@ -
  • ">Users
  • -
  • ">Seminaries
  • +
  • ">
  • +
  • ">
  • diff --git a/views/html/seminaries/index.tpl b/views/html/seminaries/index.tpl index 267a561c..037f718e 100644 --- a/views/html/seminaries/index.tpl +++ b/views/html/seminaries/index.tpl @@ -1,9 +1,10 @@ +

    • - erstellt von +
    • diff --git a/views/html/seminaries/seminary.tpl b/views/html/seminaries/seminary.tpl index 5566aba2..094fbf3b 100644 --- a/views/html/seminaries/seminary.tpl +++ b/views/html/seminaries/seminary.tpl @@ -1,4 +1,5 @@ +

      - erstellt am +

      diff --git a/views/html/users/index.tpl b/views/html/users/index.tpl index 347743bb..3b94e6a0 100644 --- a/views/html/users/index.tpl +++ b/views/html/users/index.tpl @@ -1,9 +1,10 @@ +

      • - registriert seit +
      • diff --git a/views/html/users/user.tpl b/views/html/users/user.tpl index f89d38b7..91591dd3 100644 --- a/views/html/users/user.tpl +++ b/views/html/users/user.tpl @@ -1,4 +1,5 @@ +

        - registriert seit +