Ejemplo n.º 1
0
 /**
  * Create the test locale file.
  */
 function execute()
 {
     Locale::initialize();
     $localeFiles =& Locale::getLocaleFiles();
     $localeFile = array_shift($localeFiles[$this->inLocale]);
     $localeData = LocaleFile::load($localeFile->filename);
     if (!isset($localeData)) {
         printf('Invalid locale \'%s\'', $this->inLocale);
         exit(1);
     }
     $outFile = sprintf('locale/%s/locale.xml', $this->outLocale);
     $fp = fopen($outFile, 'wb');
     if (!$fp) {
         printf('Failed to write to \'%s\'', $outFile);
         exit(1);
     }
     fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . "<!DOCTYPE locale SYSTEM \"../locale.dtd\">\n\n" . "<!--\n" . "  * locale.xml\n" . "  *\n" . "  * Copyright (c) 2003-2007 John Willinsky\n" . "  * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.\n" . "  *\n" . sprintf("  * Localization strings for the %s (%s) locale.\n", $this->outLocale, DEFAULT_OUT_LOCALE_NAME) . "  *\n" . "  * \$Id\$\n" . "  -->\n\n" . sprintf("<locale name=\"%s\" full_name=\"%s\">\n", $this->outLocale, DEFAULT_OUT_LOCALE_NAME));
     foreach ($localeData as $key => $message) {
         $outMessage = $this->fancifyString($message);
         if (strstr($outMessage, '<') || strstr($outMessage, '>')) {
             $outMessage = '<![CDATA[' . $outMessage . ']]>';
         }
         fwrite($fp, sprintf("\t<message key=\"%s\">%s</message>\n", $key, $outMessage));
     }
     fwrite($fp, "</locale>\n");
     fclose($fp);
 }
Ejemplo n.º 2
0
 function register($category, $path)
 {
     if (parent::register($category, $path)) {
         $this->addLocaleData();
         if ($this->getEnabled()) {
             // Add custom locale data for already registered locale files.
             $locale = Locale::getLocale();
             $localeFiles = Locale::getLocaleFiles($locale);
             $journal = Request::getJournal();
             $journalId = $journal->getId();
             $publicFilesDir = Config::getVar('files', 'public_files_dir');
             $customLocalePathBase = $publicFilesDir . DIRECTORY_SEPARATOR . 'journals' . DIRECTORY_SEPARATOR . $journalId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR;
             import('file.FileManager');
             foreach ($localeFiles as $localeFile) {
                 $customLocalePath = $customLocalePathBase . $localeFile->getFilename();
                 if (FileManager::fileExists($customLocalePath)) {
                     Locale::registerLocaleFile($locale, $customLocalePath, true);
                 }
             }
             // Add custom locale data for all locale files registered after this plugin
             HookRegistry::register('PKPLocale::registerLocaleFile', array(&$this, 'addCustomLocale'));
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 3
0
 function register($category, $path)
 {
     if (parent::register($category, $path)) {
         if ($this->getEnabled()) {
             import('lib.pkp.classes.file.FileManager');
             $press = Request::getPress();
             $pressId = $press->getId();
             $locale = Locale::getLocale();
             $localeFiles = Locale::getLocaleFiles($locale);
             $publicFilesDir = Config::getVar('files', 'public_files_dir');
             $customLocaleDir = $publicFilesDir . DIRECTORY_SEPARATOR . 'presses' . DIRECTORY_SEPARATOR . $pressId . DIRECTORY_SEPARATOR . CUSTOM_LOCALE_DIR;
             foreach ($localeFiles as $localeFile) {
                 $localeFilename = $localeFile->getFilename();
                 $customLocalePath = $customLocaleDir . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $localeFilename;
                 if (FileManager::fileExists($customLocalePath)) {
                     Locale::registerLocaleFile($locale, $customLocalePath, true);
                 }
             }
         }
         return true;
     }
     return false;
 }
Ejemplo n.º 4
0
 /**
  * Register a locale file against the current list.
  * @param $locale string Locale key
  * @param $filename string Filename to new locale XML file
  * @param $addToTop boolean Whether to add to the top of the list (true)
  * 	or the bottom (false). Allows overriding.
  */
 function &registerLocaleFile($locale, $filename, $addToTop = false)
 {
     $localeFiles =& Locale::getLocaleFiles($locale);
     $localeFile =& new LocaleFile($locale, $filename);
     if (!$localeFile->isValid()) {
         $localeFile = null;
         return $localeFile;
     }
     if ($addToTop) {
         // Work-around: unshift by reference.
         array_unshift($localeFiles, '');
         $localeFiles[0] =& $localeFile;
     } else {
         $localeFiles[] =& $localeFile;
     }
     return $localeFile;
 }