<?php

  /*

      lang.php

      Language related functions can be found in this file.

      ----

      THIS FILE HAS DATABASE SPECIFIC FUNCTIONS, therefore, if a
      database migration occurs, this page must be updated.

      ----

      Copyright (C) 2006  Central Manchester CLC
      Copyright (C) 2006  David Thorne (davethorne@gmail.com)

      This program is free software; you can redistribute it and/or
      modify it under the terms of the GNU General Public License
      as published by the Free Software Foundation version 2.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU General Public License for more details.

      You should have received a copy of the GNU General Public License
      along with this program; if not, write to the Free Software
      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

   */

  // Pull in required config and preferences
  require_once 'config/global.conf.php';
  require_once 'system/user_preferences.php';
  require_once 'system/templates.php';

  // Set language code to system wide default
  $_lang = $conf['default_lang'];
  if ($_SESSION['_id']) {
    // Override with user's chosen settings
    $user_prefs = get_user_prefs($_SESSION['_id']);
    if ($user_prefs['language'])
      $_lang = $user_prefs['language'];
  }
  
  /*
   * function set_text_domain()
   *
   * Parameter $dom is the gettext domain (the base of the .mo file) for all
   * subsequent bindings.
   */
  function set_text_domain($dom)
  {
    // Ensure access to language and configuration
    global $_lang, $conf;

    // Set language
    putenv("LANG=$_lang");
    setlocale(LC_ALL, $_lang);
  
    // Reset domain to current file after including sidebar
    bindtextdomain($dom, $conf['locale_dir']);
    textdomain($dom);

    // Set codeset is appropriate
    if (function_exists('bind_textdomain_codeset')) {
      bind_textdomain_codeset($dom, "UTF-8");
    }
  }

?>
