summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2018-09-08 12:48:08 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2018-09-09 12:11:12 +0200
commit222c9fed7d4ca2b3b44c05907fbb7080c1efd342 (patch)
tree62b1bfa9233000985331b9dea703d51dc24515a2 /includes
parent2d6bca1357faff28bc1f86a56b432cc463ff7574 (diff)
parent8257864829ffdfb410f05e0dd0a9c781f48b741a (diff)
Merge remote-tracking branch 'MyIgel/templating'
Diffstat (limited to 'includes')
-rw-r--r--includes/engelsystem.php8
-rw-r--r--includes/helper/email_helper.php8
-rw-r--r--includes/helper/internationalization_helper.php80
-rw-r--r--includes/includes.php1
-rw-r--r--includes/pages/guest_credits.php2
-rw-r--r--includes/pages/user_shifts.php2
-rw-r--r--includes/sys_form.php17
-rw-r--r--includes/sys_menu.php26
8 files changed, 43 insertions, 101 deletions
diff --git a/includes/engelsystem.php b/includes/engelsystem.php
index f7d813c5..4c096b43 100644
--- a/includes/engelsystem.php
+++ b/includes/engelsystem.php
@@ -16,18 +16,12 @@ require __DIR__ . '/includes.php';
* Check for maintenance
*/
if ($app->get('config')->get('maintenance')) {
- echo file_get_contents(__DIR__ . '/../templates/maintenance.html');
+ echo file_get_contents(__DIR__ . '/../templates/layouts/maintenance.html');
die();
}
/**
- * Init translations
- */
-gettext_init();
-
-
-/**
* Init authorization
*/
load_auth();
diff --git a/includes/helper/email_helper.php b/includes/helper/email_helper.php
index c223d026..8d1cb794 100644
--- a/includes/helper/email_helper.php
+++ b/includes/helper/email_helper.php
@@ -15,14 +15,16 @@ function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_it
return true;
}
- gettext_locale($recipient_user['Sprache']);
+ /** @var \Engelsystem\Helpers\Translator $translator */
+ $translator = app()->get('translator');
+ $locale = $translator->getLocale();
+ $translator->setLocale($recipient_user['Sprache']);
$message = sprintf(_('Hi %s,'), $recipient_user['Nick']) . "\n\n"
. _('here is a message for you from the engelsystem:') . "\n\n"
. $message . "\n\n"
. _('This email is autogenerated and has not been signed. You got this email because you are registered in the engelsystem.');
-
- gettext_locale();
+ $translator->setLocale($locale);
return engelsystem_email($recipient_user['email'], $title, $message);
}
diff --git a/includes/helper/internationalization_helper.php b/includes/helper/internationalization_helper.php
deleted file mode 100644
index bb6d0abd..00000000
--- a/includes/helper/internationalization_helper.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-
-/**
- * Return currently active locale
- *
- * @return string
- */
-function locale()
-{
- return session()->get('locale');
-}
-
-/**
- * Returns two letter language code from currently active locale
- *
- * @return string
- */
-function locale_short()
-{
- return substr(locale(), 0, 2);
-}
-
-/**
- * Initializes gettext for internationalization and updates the sessions locale to use for translation.
- */
-function gettext_init()
-{
- $locales = config('locales');
- $request = request();
- $session = session();
-
- if ($request->has('set_locale') && isset($locales[$request->input('set_locale')])) {
- $session->set('locale', $request->input('set_locale'));
- } elseif (!$session->has('locale')) {
- $session->set('locale', config('default_locale'));
- }
-
- gettext_locale();
- bindtextdomain('default', app('path.lang'));
- bind_textdomain_codeset('default', 'UTF-8');
- textdomain('default');
-}
-
-/**
- * Swich gettext locale.
- *
- * @param string $locale
- */
-function gettext_locale($locale = null)
-{
- if (empty($locale)) {
- $locale = session()->get('locale');
- }
-
- putenv('LC_ALL=' . $locale);
- setlocale(LC_ALL, $locale);
-}
-
-/**
- * Renders language selection.
- *
- * @return array
- */
-function make_langselect()
-{
- $request = app('request');
-
- $items = [];
- foreach (config('locales') as $locale => $name) {
- $url = url($request->getPathInfo(), ['set_locale' => $locale]);
-
- $items[] = toolbar_item_link(
- htmlspecialchars($url),
- '',
- $name,
- $locale == locale()
- );
- }
- return $items;
-}
diff --git a/includes/includes.php b/includes/includes.php
index e316e550..7a68c3c9 100644
--- a/includes/includes.php
+++ b/includes/includes.php
@@ -61,7 +61,6 @@ $includeFiles = [
__DIR__ . '/../includes/controller/user_worklog_controller.php',
__DIR__ . '/../includes/helper/graph_helper.php',
- __DIR__ . '/../includes/helper/internationalization_helper.php',
__DIR__ . '/../includes/helper/message_helper.php',
__DIR__ . '/../includes/helper/error_helper.php',
__DIR__ . '/../includes/helper/email_helper.php',
diff --git a/includes/pages/guest_credits.php b/includes/pages/guest_credits.php
index db86132d..ecfa8f7c 100644
--- a/includes/pages/guest_credits.php
+++ b/includes/pages/guest_credits.php
@@ -13,5 +13,5 @@ function credits_title()
*/
function guest_credits()
{
- return view(__DIR__ . '/../../templates/guest_credits.html');
+ return view(__DIR__ . '/../../templates/pages/credits.html');
}
diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php
index 186301db..020cfe54 100644
--- a/includes/pages/user_shifts.php
+++ b/includes/pages/user_shifts.php
@@ -224,7 +224,7 @@ function view_user_shifts()
return page([
div('col-md-12', [
msg(),
- view(__DIR__ . '/../../templates/user_shifts.html', [
+ view(__DIR__ . '/../../templates/pages/user-shifts.html', [
'title' => shifts_title(),
'room_select' => make_select($rooms, $shiftsFilter->getRooms(), 'rooms', _('Rooms')),
'start_select' => html_select_key(
diff --git a/includes/sys_form.php b/includes/sys_form.php
index c974c1d1..cd1c84e6 100644
--- a/includes/sys_form.php
+++ b/includes/sys_form.php
@@ -66,6 +66,9 @@ function form_date($name, $label, $value, $start_date = '', $end_date = '')
$value = is_numeric($value) ? date('Y-m-d', $value) : '';
$start_date = is_numeric($start_date) ? date('Y-m-d', $start_date) : '';
$end_date = is_numeric($end_date) ? date('Y-m-d', $end_date) : '';
+ $locale = $locale = session()->get('locale');
+ $shortLocale = substr($locale, 0, 2);
+
return form_element($label, '
<div class="input-group date" id="' . $dom_id . '">
<input name="' . $name . '" class="form-control" value="' . htmlspecialchars($value) . '">'
@@ -73,13 +76,13 @@ function form_date($name, $label, $value, $start_date = '', $end_date = '')
</div>
<script type="text/javascript">
$(function(){
- $(\'#' . $dom_id . '\').datepicker({
- language: \'' . locale_short() . '\',
- todayBtn: \'linked\',
- format: \'yyyy-mm-dd\',
- startDate: \'' . $start_date . '\',
- endDate: \'' . $end_date . '\',
- orientation: \'bottom\'
+ $("#' . $dom_id . '").datepicker({
+ language: "' . $shortLocale . '",
+ todayBtn: "linked",
+ format: "yyyy-mm-dd",
+ startDate: "' . $start_date . '",
+ endDate: "' . $end_date . '",
+ orientation: "bottom"
});
});
</script>
diff --git a/includes/sys_menu.php b/includes/sys_menu.php
index fae94de5..5609c0ab 100644
--- a/includes/sys_menu.php
+++ b/includes/sys_menu.php
@@ -110,7 +110,7 @@ function make_user_submenu()
{
global $privileges, $page;
- $user_submenu = make_langselect();
+ $user_submenu = make_language_select();
if (in_array('user_settings', $privileges) || in_array('logout', $privileges)) {
$user_submenu[] = toolbar_item_divider();
@@ -228,6 +228,30 @@ function make_room_navigation($menu)
}
/**
+ * Renders language selection.
+ *
+ * @return array
+ */
+function make_language_select()
+{
+ $request = app('request');
+ $activeLocale = session()->get('locale');
+
+ $items = [];
+ foreach (config('locales') as $locale => $name) {
+ $url = url($request->getPathInfo(), ['set-locale' => $locale]);
+
+ $items[] = toolbar_item_link(
+ htmlspecialchars($url),
+ '',
+ $name,
+ $locale == $activeLocale
+ );
+ }
+ return $items;
+}
+
+/**
* @return string
*/
function make_menu()