/**
  * Get a list of locale files for the given locale code.
  * @param $locale string Locale code
  * @return array List of filenames
  */
 function getLocaleFiles($locale)
 {
     if (!AppLocale::isLocaleValid($locale)) {
         return null;
     }
     $localeFiles = AppLocale::getFilenameComponentMap($locale);
     $plugins =& PluginRegistry::loadAllPlugins();
     foreach (array_keys($plugins) as $key) {
         $plugin =& $plugins[$key];
         $localeFile = $plugin->getLocaleFilename($locale);
         if (!empty($localeFile)) {
             if (is_scalar($localeFile)) {
                 $localeFiles[] = $localeFile;
             }
             if (is_array($localeFile)) {
                 $localeFiles = array_merge($localeFiles, $localeFile);
             }
         }
         unset($plugin);
     }
     return $localeFiles;
 }
 function requireComponents($components, $locale = null)
 {
     $loadedComponents =& Registry::get('loadedLocaleComponents', true, array());
     if ($locale === null) {
         $locale = AppLocale::getLocale();
     }
     $filenameComponentMap = AppLocale::getFilenameComponentMap($locale);
     foreach ($components as $component) {
         // Don't load components twice
         if (isset($loadedComponents[$locale][$component])) {
             continue;
         }
         if (!isset($filenameComponentMap[$component])) {
             fatalError('Unknown locale component ' . $component);
         }
         $filename = $filenameComponentMap[$component];
         AppLocale::registerLocaleFile($locale, $filename);
         $loadedComponents[$locale][$component] = true;
     }
 }
 /**
  * Test all locale files for the supplied locale against the supplied
  * reference locale, returning an array of errors.
  * @param $locale string Name of locale to test
  * @param $referenceLocale string Name of locale to test against
  * @return array
  */
 function testLocale($locale, $referenceLocale)
 {
     $localeFileNames = AppLocale::getFilenameComponentMap($locale);
     $errors = array();
     foreach ($localeFileNames as $localeFileName) {
         $referenceLocaleFileName = str_replace($locale, $referenceLocale, $localeFileName);
         $localeFile = new LocaleFile($locale, $localeFileName);
         $referenceLocaleFile = new LocaleFile($referenceLocale, $referenceLocaleFileName);
         $errors = array_merge_recursive($errors, $localeFile->testLocale($referenceLocaleFile));
         unset($localeFile);
         unset($referenceLocaleFile);
     }
     $plugins =& PluginRegistry::loadAllPlugins();
     foreach (array_keys($plugins) as $key) {
         $plugin =& $plugins[$key];
         $referenceLocaleFilenames = $plugin->getLocaleFilename($referenceLocale);
         if ($referenceLocaleFilenames) {
             if (is_scalar($referenceLocaleFilenames)) {
                 $referenceLocaleFilenames = array($referenceLocaleFilenames);
             }
             $localeFilenames = $plugin->getLocaleFilename($locale);
             if (is_scalar($localeFilenames)) {
                 $localeFilenames = array($localeFilenames);
             }
             assert(count($localeFilenames) == count($referenceLocaleFilenames));
             foreach ($referenceLocaleFilenames as $index => $referenceLocaleFilename) {
                 assert(isset($localeFilenames[$index]));
                 $localeFile = new LocaleFile($locale, $localeFilenames[$index]);
                 $referenceLocaleFile = new LocaleFile($referenceLocale, $referenceLocaleFilename);
                 $errors = array_merge_recursive($errors, $localeFile->testLocale($referenceLocaleFile));
                 unset($localeFile);
                 unset($referenceLocaleFile);
             }
         }
         unset($plugin);
     }
     return $errors;
 }
Example #4
0
 /**
  * Load a set of locale components. Parameters of mixed length may
  * be supplied, each a LOCALE_COMPONENT_... constant. An optional final
  * parameter may be supplied to specify the locale (e.g. 'en_US').
  */
 static function requireComponents()
 {
     $params = func_get_args();
     $paramCount = count($params);
     if ($paramCount === 0) {
         return;
     }
     // Get the locale
     $lastParam = $params[$paramCount - 1];
     if (is_string($lastParam)) {
         $locale = $lastParam;
         $paramCount--;
     } else {
         $locale = AppLocale::getLocale();
     }
     // Backwards compatibility: the list used to be supplied
     // as an array in the first parameter.
     if (is_array($params[0])) {
         $params = $params[0];
         $paramCount = count($params);
     }
     // Go through and make sure each component is loaded if valid.
     $loadedComponents =& Registry::get('loadedLocaleComponents', true, array());
     $filenameComponentMap = AppLocale::getFilenameComponentMap($locale);
     for ($i = 0; $i < $paramCount; $i++) {
         $component = $params[$i];
         // Don't load components twice
         if (isset($loadedComponents[$locale][$component])) {
             continue;
         }
         // Validate component
         if (!isset($filenameComponentMap[$component])) {
             fatalError('Unknown locale component ' . $component);
         }
         $filename = $filenameComponentMap[$component];
         AppLocale::registerLocaleFile($locale, $filename);
         $loadedComponents[$locale][$component] = true;
     }
 }