/**
  * @static
  * Static method that offers some kind of locale factory. Since the Locale object
  * better not use a Singleton (otherwise we couldn't use more than one locale file
  * at a time) this function has been included here to provide a system similar to
  * a singleton: we keep an static array inside the function, that contains all the
  * locale files that have been loaded so far. Whenever somebody requests a locale
  * to be fetched from disk, we will first check that we have not loaded it before. If
  * we have, then we only have to return the same object we were keeping.
  * If the locale wasn't there, we will then load it from disk and store/cache the
  * resulting object for future use.
  * It is recommended to use this method over creating new Locale objects every time
  * we need one.
  *
  * @param localeCode The code (eg. en_UK, es_ES) of the locale we want to get.
  * @return Returns a Locale object corresponding to the requested locale.
  * @see Locale
  */
 function &getLocale($localeCode = null)
 {
     // array to keep track of the locales that we have already loaded, so that
     // we don't have to fetch them from disk
     static $loadedLocales;
     // if there is no locale parameter, we use the default one
     if ($localeCode == null) {
         $config =& Config::getConfig();
         $localeCode = $config->getValue("default_locale");
     }
     // check if we have already loaded that locale or else, load it from
     // disk and keep it for later, just in case anybody asks again
     if (isset($loadedLocales[$localeCode])) {
         $locale = $loadedLocales[$localeCode];
     } else {
         $locale = new Locale($localeCode);
         $pm =& PluginManager::getPluginManager();
         foreach ($pm->_pluginList as $pluginId) {
             if ($pm->pluginHasLocale($pluginId, $localeCode)) {
                 // if the plugin provides the locale that we need, continue
                 $pluginLocale = Locales::getPluginLocale($pluginId, $localeCode);
             } else {
                 // if not, try to load en_UK by default
                 if ($pm->pluginHasLocale($pluginId, "en_UK")) {
                     $pluginLocale = Locales::getPluginLocale($pluginId, "en_UK");
                 }
                 // if not en_UK locale available, forget about it...
             }
             // merge the plugin locale with the big locale
             if (isset($pluginLocale)) {
                 $locale->mergeLocale($pluginLocale);
             }
         }
         $loadedLocales[$localeCode] = $locale;
     }
     return $locale;
 }
 /**
  * @private
  */
 function _loadPluginLocale($pluginId, $locale)
 {
     return Locales::getPluginLocale($pluginId, $locale);
 }