Example #1
0
 public static function getTranslationHandler()
 {
     if (self::$translation_handler === NULL) {
         if (self::useGetTextExtension() == TRUE) {
             //Debug::Text('Using getText()...', __FILE__, __LINE__, __METHOD__,10);
             return new NativeGettextTranslationHandler();
         } else {
             //Debug::Text('Using Translation2...', __FILE__, __LINE__, __METHOD__,10);
             require_once 'Translation2.php';
             $locale_dir = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'interface' . DIRECTORY_SEPARATOR . 'locale' . DIRECTORY_SEPARATOR;
             // The Translation2 Gettext example has this comment:
             //
             //    "Better set prefetch to FALSE for the gettext container, so we don't need
             //     to read in the whole MO file with File_Gettext on every request."
             //
             // I haven't investigated this fully yet.  So for now I am doing as they advise.
             // Probably worth checking out for performance purposes. Also, it is unclear
             // how this affects PO mode, as opposed to MO.
             $params = array('prefetch' => FALSE, 'langs_avail_file' => $locale_dir . 'langs.ini', 'domains_path_file' => $locale_dir . 'domains.ini', 'default_domain' => 'messages', 'file_type' => 'mo', 'cacheDir' => '/tmp/timetrex/', 'lifeTime' => 86400 * 7);
             self::$translation_handler = Translation2::factory('gettext', $params);
             //self::$translation_handler->getDecorator('CacheLiteFunction');
             // Okay, this is super-gross, as we are modifying private data of the
             // Translation2::storage object.  Why do we do it?  Because the
             // brain-dead Translation2 api for gettext only allows specifying
             // fixed paths via domains.ini file.  Our path depends on our environment
             // and we need to tell it that.  So, it appears we either do this nasty
             // hack, or we have to start modifying the Translation2 code directly.
             self::$translation_handler->storage->_domains = array('messages' => $locale_dir);
         }
     }
     return self::$translation_handler;
 }