An error occurred while loading the file. Please try again.
-
dockx thibault authored
Space parenthesis after fnc name fixed On function creation
Verifieda02916c6
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 FusionDirectory
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; either version 2 of the License, or
(at your option) any later version.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*!
* \file class_Language.inc
* Source code for the class Language
*/
/*!
* \brief This class contains all the function needed to manage languages
*/
class Language
{
/*!
* \brief Initialize language configuration
*
* \param string $lang Language locale to use, defaults to self::detect()
*/
public static function init ($lang = NULL)
{
global $BASE_DIR;
if ($lang === NULL) {
$lang = static::detect();
}
list ($language, $country, $char) = parse_gettext_lang($lang);
putenv('LANGUAGE=');
putenv("LANG=$lang");
$langset = setlocale(LC_ALL, $lang, $language.'.'.$char);
if ($langset === FALSE) {
trigger_error('Setting locale to '.$lang.' failed');
} elseif ($langset != $lang) {
trigger_error('Setting locale to '.$lang.' failed, fell back to '.$langset);
}
$GLOBALS['t_language'] = $lang;
$GLOBALS['t_gettext_message_dir'] = $BASE_DIR.'/locale/';
static::setHeaders($lang, 'text/html');
/* Set the text domain as 'fusiondirectory' */
$domain = 'fusiondirectory';
bindtextdomain($domain, LOCALE_DIR);
textdomain($domain);
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $lang, 'Setting language to');
}
$ret = FALSE;
/* Reset plist cache if language changed */
if ((!session::is_set('lang')) || (session::get('lang') != $lang)) {
$ret = TRUE;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
if (session::is_set('plist')) {
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
@DEBUG(DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, session::get ('lang'), 'Plist already loaded with language');
}
session::un_set('plist');
session::set('lang', $lang);
load_plist();
}
}
session::set('lang', $lang);
return $ret;
}
/*!
* \brief Determine which language to show to the user
*
* Determines which language should be used to present fusiondirectory content
* to the user. It does so by looking at several possibilites and returning
* the first setting that can be found.
*
* -# Language configured by the user
* -# Global configured language
* -# Language as returned by al2gt (as configured in the browser)
*
* \return string gettext locale string
*/
public static function detect ()
{
global $config;
/* Try to use users primary language */
$ui = get_userinfo();
if (isset($ui) && ($ui !== NULL) && ($ui->language != '')) {
return $ui->language.'.UTF-8';
}
/* Check for global language settings in configuration */
if (isset($config) && ($config->get_cfg_value('language') != '')) {
$lang = $config->get_cfg_value('language');
if (!preg_match('/utf/i', $lang)) {
$lang .= '.UTF-8';
}
return $lang;
}
/* Load supported languages */
$languages = static::getList();
/* Move supported languages to flat list */
$langs = [];
foreach (array_keys($languages) as $lang) {
$langs[] = $lang.'.UTF-8';
}
/* Return gettext based string */
return al2gt($langs);
}
/*!
* \brief Get the language for the user connecting
*
* \param boolean $ownLanguage Should language names be stated in their own language as well
*/
public static function getList ($ownLanguage = FALSE)
{
/* locales in english */
$tmp_english = [
'en_US' => 'English',
'af_ZA' => 'Afrikaans',