From 96a263f7129fbcf01ef644c531cdcc0a0be59085 Mon Sep 17 00:00:00 2001 From: Philip Häusler Date: Mon, 25 Nov 2013 19:12:19 +0100 Subject: initial gettext integration --- includes/helper/internationalization_helper.php | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 includes/helper/internationalization_helper.php (limited to 'includes/helper') 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 @@ + "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 = '

'; + foreach ($locales as $locale => $name) + $html .= '' . $name . ''; + $html .= '

'; + return ''; +} + +?> \ No newline at end of file -- cgit v1.2.3-54-g00ecf