/* Enjoy!!! Dino Ciuffetti - dam2k@users.sourceforge.net
*
*
* 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 of the License.
*
* 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 (COPYING); if not, go to http://www.fsf.org/ or write
* to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*
*/
/* INTERNATIONALIZATION CLASS */
/**
* Here you can i18n your own strings. For example, cmsdam uses this class to handle strings in a geographic
* portable way.
* Class instance: $cms->i18n
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
class cmsdam_i18n
{
/**
* You shouldn't use this variable from your sections
* @access private
*/
var $logs;
/**
* You shouldn't use this variable from your sections
* @access private
*/
var $plugins;
/**
* You shouldn't use this variable from your sections
* @access private
*/
var $sections;
var $core_lang_dir;
var $core_lang_file;
var $user_lang_dir;
var $preferred_language;
var $http;
var $lang;
/**
* Class constructor
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function cmsdam_i18n() {
$this->preferred_language = "";
// This is the directory that contains cmsdam core lang files
$this->core_lang_dir = "classes/i18n";
// This is the main lang file, it is contained in the lang directory
$this->core_lang_file = "lang.php";
include ($this->core_lang_dir . "/" . $this->core_lang_file);
$this->lang = new cmsdam_reserved_lang;
return true;
}
/**
* Add a i18n string onto the given lang stack. Note that you cannot have spaces or strange chars
* in the key name.
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
* @param str lang The language
* @param str key The key name to i18n
* @param str val The value to i18n
* @return bool False on error, True on success
*/
function cmsdam_addstring($lang, $key, $val) {
if (($lang == "") || ($key == "") || (strstr($key, ' ') != FALSE)) { // Key name is NOT valid
$this->logs->log_note (3, "i18n: cmsdam_addstring: the passed key is not valid.");
return false;
}
// Adds a new element for the lang array
$this->lang->add_element($lang, $key, $val);
return true;
}
/**
* Get a i18n string from the given lang stack.
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
* @param str lang The language
* @param str key The key name to i18n
* @return str The i18n string for the given language
*/
function cmsdam_getstring($lang, $key) {
return $this->lang->get_element($lang, $key);
}
/**
* Set the preferred language. If lang is not passed, cmsdAm set the default language using
* the preferred language of the browser, where possible. You can use the setted language to get internationalized
* string with the method cmsdam_getstring().
* Please note that if the cookie cmsdam_lang exists, cmsdam will set the preferred language using
* that cookie by default.
* This method overrides the lang cookie, and a new one will be generated.
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
* @param str lang The language to set as cmsdam default
* @param int reload If reload == 1 cmsdam will reload the same section
* @return str The setted language code
*/
function cmsdam_set_preferred_lang($lang="", $reload=0) {
if (($this->preferred_language == "") && ($lang=="")) { // no language already defined by cookie cmsdam_lang
$this->preferred_language = $this->http->browser_languages(); // get the language selection from the browser
$this->preferred_language = $this->preferred_language[0];
if ($this->preferred_language == "") { // Setting default language to "en"
$this->preferred_language = "en";
}
}
if ($lang != "") {
$this->preferred_language = $lang;
}
// Lang cookie will expire in 30 days
setcookie ("cmsdam_lang", $this->preferred_language, time()+2592000);
if ($reload == 1) {
$this->plugins->plugin_include("http_relocator");
$this->plugins->included->http_relocator->api->CmsDam_HTTP_relocator_SendToSectionNOCache($this->sections->section_requested);
}
$this->logs->log_note(5, "NOTE: cmsdam preferred language setted to: " . $this->preferred_language);
return $this->preferred_language;
}
/**
* Returns the cmsdam default language. You can set this value with the cmsdam_set_preferred_lang()
* method. The returned value can be used, for example, to get an internationalized string with
* cmsdam_getstring().
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
* @return str The setted language code, or false if it is not setted
*/
function cmsdam_get_preferred_lang() {
if ($this->preferred_language == "") {
return false;
}
return $this->preferred_language;
}
}
?>