Bug 396 - Localize the Auth service (in German); including some fixes to make code...
[authserver.git] / app / authsystem.inc.php
index 6e30200293422d7fa3dd9fd5c26d6c7669649b1c..068fb2fadae62ed8fa6fa40b519f634d60a10880 100644 (file)
@@ -26,14 +26,25 @@ require_once('../kairo-utils/email.php-class');
 // Class for sending emails
 require_once(__DIR__.'/authutils.php-class');
 
-bindtextdomain('kairo_auth', 'en'); // XXX: Should negotiate locale.
-bind_textdomain_codeset('kairo_auth', 'utf-8');
-
 // Connect to our MySQL DB
 $db = new PDO($dbdata['dsn'], $dbdata['username'], $dbdata['password']);
 // Instantiate auth utils.
 $utils = new AuthUtils($settings, $db);
 
+// This is an array of locale tags in browser style mapping to unix system locale codes to use with gettext.
+$supported_locales = array(
+    'en-US' => 'en_US',
+    'de' => 'de_DE',
+);
+
+$textdomain = 'kairo_auth';
+$textlocale = $utils->negotiateLocale(array_keys($supported_locales));
+putenv('LC_ALL='.$supported_locales[$textlocale]);
+$selectedlocale = setlocale(LC_ALL, $supported_locales[$textlocale]);
+bindtextdomain($textdomain, '../locale');
+bind_textdomain_codeset($textdomain, 'utf-8');
+textdomain($textdomain);
+
 /* Creating the DB tables:
 CREATE TABLE `auth_sessions` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT ,