summaryrefslogtreecommitdiff
path: root/includes/helper
diff options
context:
space:
mode:
authorPhilip Häusler <msquare@notrademark.de>2013-11-25 19:12:19 +0100
committerPhilip Häusler <msquare@notrademark.de>2013-11-25 19:12:19 +0100
commit96a263f7129fbcf01ef644c531cdcc0a0be59085 (patch)
tree1dcb780aad3926e308a7daae9db5d88ca4d459f6 /includes/helper
parent33b97e3ad3f4baa82bb754c46134554c90b30346 (diff)
initial gettext integration
Diffstat (limited to 'includes/helper')
-rw-r--r--includes/helper/internationalization_helper.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/includes/helper/internationalization_helper.php b/includes/helper/internationalization_helper.php
new file mode 100644
index 00000000..ae88eb21
--- /dev/null
+++ b/includes/helper/internationalization_helper.php
@@ -0,0 +1,43 @@
+<?php
+$locales = array(
+ 'de_DE.UTF-8' => "Deutsch",
+ 'en_US.UTF-8' => "English"
+);
+
+$default_locale = 'en_US.UTF-8';
+
+/**
+ * Initializes gettext for internationalization and updates the sessions locale to use for translation.
+ */
+function gettext_init() {
+ global $locales, $default_locale;
+
+ if (isset($_REQUEST['set_locale']) && in_array($_REQUEST['set_locale'], array_keys($locales)))
+ $_SESSION['locale'] = $_REQUEST['set_locale'];
+ elseif (! isset($_SESSION['locale']))
+ $_SESSION['locale'] = $default_locale;
+
+ putenv('LC_ALL=' . $_SESSION['locale']);
+ setlocale(LC_ALL, $_SESSION['locale']);
+ bindtextdomain('default', '../locale');
+ bind_textdomain_codeset('default', 'UTF-8');
+ textdomain('default');
+}
+
+/**
+ * Renders language selection.
+ *
+ * @return string
+ */
+function make_langselect() {
+ global $locales;
+ $URL = $_SERVER["REQUEST_URI"] . (strpos($_SERVER["REQUEST_URI"], "?") > 0 ? '&' : '?') . "set_locale=";
+
+ $html = '<p class="content">';
+ foreach ($locales as $locale => $name)
+ $html .= '<a class="sprache" href="' . htmlspecialchars($URL) . $locale . '"><img src="pic/flag/' . $locale . '.png" alt="' . $name . '" title="' . $name . '"></a>';
+ $html .= '</p>';
+ return '<nav class="container"><h4>' . _("Language") . '</h4>' . $html . '</nav>';
+}
+
+?> \ No newline at end of file