- Timestamp:
- Jan 17, 2010, 7:05:35 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/AMetaData/JpegMetaData/Common/Locale.class.php
r4686 r4698 35 35 * The Locale class is used for tag translation, reading the .mo files 36 36 * 37 * There is one directory per language, the directories tree must respect this 38 * structure 39 * 40 * --\ Locale => main directory for languages 41 * | 42 * +--\ en_UK => language 43 * | | 44 * | +--\ LC_MESSAGES 45 * | | 46 * | +--\ Tag.mo => names & values translations 47 * | +--\ TadDesc.mo => descriptions translations 48 * | 49 * +--\ fr_FR 50 * | 51 * +--\ LC_MESSAGES 52 * | 53 * +--\ Tag.mo 54 * +--\ TadDesc.mo 55 * 56 * 37 57 * ----------------------------------------------------------------------------- 38 58 * 59 * .. Notes .. 60 * 61 * This class don't use the PHP gettext functions, but the php-gettext extension 62 * ==> See files in External/php-gettext for more information about this project 63 * 64 * 65 * 66 * This class provides theses public functions : 67 * - (static) setLanguage 68 * - (static) getLanguage 69 * - (static) get 70 * - (static) getDesc 39 71 * 40 72 * ----------------------------------------------------------------------------- … … 44 76 require_once(JPEG_METADATA_DIR."External/php-gettext/gettext.inc"); 45 77 46 $supported_locales = array('en_UK'); 78 /** 79 * $supported_locales is a global variable need by the php-gettext package. 80 * the array is automatically initialized with the setLanguage() function 81 */ 82 $supported_locales = array(); 83 84 /** 85 * assume a default language is set in any case... 86 */ 87 Locale::setLanguage(); 88 47 89 48 90 class Locale … … 51 93 const JMD_TAGDESC = "TagDesc"; 52 94 53 static function set($language) 95 static private $language = ""; 96 97 /** 98 * This function is used to set the locale language. 99 * If no language is given, assume the default "en_UK" language 100 * 101 * If there is no translation file for the the given language, assume the 102 * default "en_UK" language 103 * 104 * @param String $language : the language 105 * @return String : the defined language 106 */ 107 static function setLanguage($language="en_UK") 54 108 { 55 T_setlocale(LC_MESSAGES, $language);109 global $supported_locales; 56 110 111 /* 112 * Scan the Locale directory. 113 * Any directory with a sub directory "LC_MESSAGES" is considered as a 114 * supported locale language 115 */ 116 $directory=scandir(JPEG_METADATA_DIR."Locale"); 117 foreach($directory as $key => $file) 118 { 119 if(is_dir(JPEG_METADATA_DIR."Locale/".$file) and 120 $file!='.' and 121 $file!='..' and 122 file_exists(JPEG_METADATA_DIR."Locale/".$file."/LC_MESSAGES/Tag.mo")) 123 $supported_locales[]=$file; 124 125 } 126 127 /* 128 * if the desired language doesn't exist, apply the en_UK locale 129 * (assuming the en_UK exists and was not deleted) 130 */ 131 if(!in_array($language, $supported_locales)) 132 self::$language='en_UK'; 133 else 134 self::$language=$language; 135 136 /* 137 * set the locale 138 */ 139 T_setlocale(LC_MESSAGES, self::$language); 140 141 /* 142 * set one domain "TAG" for tags name&values, and one domaine "TAGDESC" for 143 * tags description 144 */ 57 145 T_bindtextdomain(self::JMD_TAG, dirname(dirname(__FILE__))."/Locale"); 58 146 T_bindtextdomain(self::JMD_TAGDESC, dirname(dirname(__FILE__))."/Locale"); 147 148 return(self::$language); 59 149 } 60 150 61 static function get($tagName) 151 /** 152 * returns the defined current language 153 * 154 * @return String 155 */ 156 static function getLanguage() 62 157 { 63 return( @T_dgettext(self::JMD_TAG, $tagName));158 return(self::$language); 64 159 } 65 160 161 /** 162 * returns the translation in current language for the given key 163 * 164 * @return String 165 */ 166 static function get($key) 167 { 168 return(@T_dgettext(self::JMD_TAG, $key)); 169 } 170 171 /** 172 * returns the description in current language for the given tagName 173 * 174 * @return String 175 */ 66 176 static function getDesc($tagName) 67 177 {
Note: See TracChangeset
for help on using the changeset viewer.