<?php
/**
* CyCle IDE, Gettext Manager
*
* @author Leon Pegg
* @package CyCleIDE
*/
# Note : all constants should be UPPERCASE and words separated with _
# Note : all classes should be CamelCaps no _
# Note : methods and class properties should all have modifiers (public/private/protected)
# Note : static modifiers must precede method and properties modifiers (public/private/protected)
# Note : all variables should be lowercase no _
# Note : all methods/functions should be lowercase and words seperated with _
# Note : { should not be on new line
require_once('ini.php');
if (!extension_loaded('xml')) {
echo 'The XML Extention is not present.';
die();
}
if (!function_exists('gettext')) {
function bind_textdomain_codeset($domain, $codeset ){}
function bindtextdomain($domain, $directory){}
function dcgettext($domain, $message, $category){}
function dcngettext($domain, $msgid1, $msgid2, $n, $category){}
function dgettext($domain, $message){}
function dngettext($domain, $msgid1, $msgid2, $n){}
function gettext($message){return $message;}
function ngettext($msgid1, $msgid2, $n){}
function textdomain($textdomain){}
function _($message){return $message;}
define('GETTEXT_SUPPORTED', false);
} else {
define('GETTEXT_SUPPORTED', true);
}
class Gettext {
const SUPPORTED = GETTEXT_SUPPORTED;
static private $instance = null;
protected $country = 'GB';
protected $language = 'en';
protected $languages = array('GB' => array('en' => 'en'));
protected $countrylong = array('GB' => 'Britain (UK).');
protected $languagelong = array('en' => 'English.');
protected function __construct() {
if (Gettext::SUPPORTED == false) {
return;
}
// singlton
}
static public function get_instance() {
if (self::$instance == null) {
self::$instance = new self;
}
return self::$instance;
}
public function get_countries() {
// get countries
$countries = array();
foreach ($this->languages as $country => $languages) {
$countries[] = $country;
}
return $countries;
}
public function get_languages($country) {
// get languages
return $this->languages[$country];
}
public function set_language($country, $language) {
// set language
if (array_search($language,$this->languages[$country])) {
$this->country = $country;
$this->language = $language;
$code = $language.'_'.$country;
$domain = 'cycle';
bindtextdomain($domain, Ide::LOCALE_DIR);
textdomain($domain);
putenv("LANG=$code");
setlocale(LC_ALL, $code);
}
}
public function get_language() {
return $this->language;
}
public function get_language_long($language){
return $this->languagelong[$language];
}
public function get_country_long($country){
return $this->countrylong[$country];
}
public function get_country() {
return $this->country;
}
}
$settings = Ini::get_instance();
$gettext = Gettext::get_instance();
$country = $settings->get_value('gettext', 'country');
$language = $settings->get_value('gettext', 'language');
echo $gettext->get_language_long($language).' '.$gettext->get_country_long($country)."\n";
$gettext->set_language($country, $language);
?>