<?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 linerequire_once('ini.php');// check for xml extention as needed by IdeGettextif (!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);}/** * Gettext manager * */class IdeGettext { /** * Is gettext supported? * */ const SUPPORTED = GETTEXT_SUPPORTED; /** * An instance of IdeGettext * * @var IdeGettext */ static private $instance = null; /** * Current country code * * @var string */ protected $country = 'GB'; /** * Current language code * * @var string */ protected $language = 'en'; /** * Installed languages * * @var array */ protected $languages = array('GB' => array('en' => 'en')); /** * Full country names * * @var array */ protected $countrylong = array('GB' => 'Britain (UK).'); /** * Full language names * * @var array */ protected $languagelong = array('en' => 'English.'); protected function __construct() { if (IdeGettext::SUPPORTED == false) { return; } // singlton } protected function __clone(){ // singlton } /** * Get an instance of IdeGettext * * @return IdeGettext */ static public function get_instance() { if (self::$instance == null) { self::$instance = new self; } return self::$instance; } /** * Get an array of installed countries * * @return array */ public function get_countries() { // get countries $countries = array(); foreach ($this->languages as $country => $languages) { $countries[] = $country; } return $countries; } /** * Get an array of installed languages for country * * @param string_type $country * @return array */ public function get_languages($country) { // get languages return $this->languages[$country]; } /** * Set gettext to langauge * * @param string $country * @param string $language */ 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"); // windows is stupid and needs this trick putenv("LANGUAGE=$code"); // windows is stupid and needs this trick setlocale(LC_ALL, $code); return true; } return false; } /** * Get current language code * * @return string */ public function get_language() { return $this->language; } /** * Get language full name * * @param string $language * @return string */ public function get_language_long($language){ return $this->languagelong[$language]; } /** * Get country full name * * @param string $country * @return string */ public function get_country_long($country){ return $this->countrylong[$country]; } /** * Get current country code * * @return string */ public function get_country() { return $this->country; }}$settings = IdeIni::get_instance();$gettext = IdeGettext::get_instance();$country = $settings->get_value('gettext', 'country');$language = $settings->get_value('gettext', 'language');if (!$gettext->set_language($country, $language)) { echo sprintf(gettext('Setting language to %s_%s : failed droping to default'), $language, $country)."\n";} else { echo sprintf(gettext('Setting language to %s_%s : sucsessful'), $language, $country)."\n";}?>