<?php
/*
 * This file is part of Web Pro Manager.
 * 
 * Web Pro Manager 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 3 of the License, or
 * (at your option) any later version.
 * 
 * Web Pro Manager 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 Web Pro Manager.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * @author The Web Pro Miami, Inc. <info@thewebpro.com>
 * @copyright The Web Pro Miami, Inc. <info@thewebpro.com>, http://www.thewebpro.com/
 * @license http://www.gnu.org/licenses/gpl.html GNU GPL
 * @package WebProManager
*/

// Support for servers with php_gettext installed
define('PROJECT_DIR', realpath('./'));
if(PHP_OS == 'WINNT'){ define('LOCALE_DIR', PROJECT_DIR .'\lang'); } else { define('LOCALE_DIR', PROJECT_DIR .'/lang'); }
define('DEFAULT_LOCALE', 'en_US');
if(file_exists("../inc/gettext.inc")){ require_once("../inc/gettext.inc"); } else { require_once("../../inc/gettext.inc"); }

// Internationalization for back-end
if(!isset($nUserLangChoice)){ $nUserLangChoice = ""; }
if(!$nUserLangChoice && isset($nDefaultLang)){ $nUserLangChoice = $nDefaultLang; }
switch($nUserLangChoice){
	case "en": $nLocale = "en_US"; break; // English
	case "es": $nLocale = "es_ES"; break; // Spanish
	case "de": $nLocale = "de_DE"; break; // German
	case "fr": $nLocale = "fr_FR"; break; // French
	case "it": $nLocale = "it_IT"; break; // Italian
	case "pt": $nLocale = "pt_PT"; break; // Portuguese
	case "sb": $nLocale = "sr_RS"; break; // Serbian
	case "gl": $nLocale = "gl_ES"; break; // Galician
	default: $nLocale = "en_US"; break; // English (default)
}
$nLocaleDirectory = "lang";
$nLocaleDomain = "messages";
$nLocalDirectoryOffset = "";

// Basic settings
putenv("LANG=$nLocale");
setlocale(LC_ALL, $nLocale);
setlocale(LC_TIME, $nLocale);

// Setup paths (important to stop caching of updated language files)
$nLocaleDomainFinal = "$nLocaleDomain";
if(!file_exists($nLocaleDirectory)){ $nLocalDirectoryOffset = "../"; }
$nLangFilePath = "$nLocalDirectoryOffset$nLocaleDirectory/$nLocale/LC_MESSAGES/$nLocaleDomain.mo";
if(file_exists($nLangFilePath)){
	$nLangFilePathMTime = filemtime($nLangFilePath); // check its modification time
	$nLocaleDomainFinal = "{$nLocaleDomain}_{$nLangFilePathMTime}";
	$nLangFilePathFinal = "$nLocalDirectoryOffset$nLocaleDirectory/$nLocale/LC_MESSAGES/$nLocaleDomainFinal.mo"; 
	if(!file_exists($nLangFilePathFinal)){ copy($nLangFilePath,$nLangFilePathFinal); }
}
// Bindings
bindtextdomain("$nLocaleDomainFinal", "$nLocalDirectoryOffset$nLocaleDirectory");
bind_textdomain_codeset("$nLocaleDomainFinal","UTF-8");
textdomain("$nLocaleDomainFinal");
?>
