[pLog-svn] r1798 - in plog/branches/plog-1.0.1/class: localeplugin

Mark Wu markplace at gmail.com
Mon Apr 11 16:44:25 GMT 2005


Hi Oscar:

I am testing ...  :D

Mark 

-----Original Message-----
From: plog-svn-bounces at devel.plogworld.net
[mailto:plog-svn-bounces at devel.plogworld.net] On Behalf Of Oscar Renalias
Sent: Tuesday, April 12, 2005 12:39 AM
To: plog-svn at devel.plogworld.net
Subject: Re: [pLog-svn] r1798 - in plog/branches/plog-1.0.1/class:
localeplugin

Mark,

did you notice this change? It should solve the issue about adding new
locales to a plugin dynamically, without changing the PluginBase::locales
array... Do you think you could give it a quick test?

Oscar

On 10 Apr 2005, at 22:28, oscar at devel.plogworld.net wrote:

> Author: oscar
> Date: 2005-04-10 19:27:59 +0000 (Sun, 10 Apr 2005)
> New Revision: 1798
>
> Modified:
>    plog/branches/plog-1.0.1/class/locale/locales.class.php
>    plog/branches/plog-1.0.1/class/plugin/pluginbase.class.php
>    plog/branches/plog-1.0.1/class/plugin/pluginmanager.class.php
> Log:
> this should allow users to add new locales to plugin dynamically,  
> without the need to alter the PluginBase::locales array as it was so  
> far. In addition to that, plugins do not load *all* the locales that  
> they provide as it was being done so far, so hopefully this will  
> reduce the memory consumption too...
>
> Modified: plog/branches/plog-1.0.1/class/locale/locales.class.php
> ===================================================================
> --- plog/branches/plog-1.0.1/class/locale/locales.class.php	2005-04-10  
> 15:39:27 UTC (rev 1797)
> +++ plog/branches/plog-1.0.1/class/locale/locales.class.php	2005-04-10  
> 19:27:59 UTC (rev 1798)
> @@ -51,7 +51,7 @@
>          {
>          	// 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;
> +        	static $loadedLocales;        	
>
>              // if there is no locale parameter, we use the default one
>          	if( $localeCode == null ) {
> @@ -66,27 +66,21 @@
>              }
>              else {
>              	$locale = new Locale( $localeCode );
> -
> -    			// check if we have any plugin locales loaded for
this language
> -    			global $_plugins_loadedLocales;
> -    			
> -    			// loop through all the plugins, and check which
ones of them  
> provide the current locale and
> -    			// which ones doesn't. If the blog uses a locale
that the  
> plugin does not provide, then we'll
> -    			// use en_UK as the default, or else we'll load the
correct  
> one.
> -    			foreach( $_plugins_loadedLocales as $pluginId =>  
> $pluginLocales ) {
> -        			 if( is_array( $pluginLocales )) {
> -        			     // let's check if the plugin has the
locale that we  
> need
> -        			     if( isset(
$pluginLocales["$localeCode"] )) {
> -        			         $locale->mergeLocale(  
> $pluginLocales["$localeCode"] );
> -        			     }
> -        			     else {
> -        			         if( isset( $pluginLocales["en_UK"]
)) {
> -        			             $locale->mergeLocale(
$pluginLocales["en_UK"]  
> );        			
> -        			         }        			
> -        			     }
> -        			 }
> -    			}
> -
> +                $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
> +                        $pluginLocale = Locales::getPluginLocale(  
> $pluginId, "en_UK" );
> +                    }
> +
> +                    // merge the plugin locale with the big locale
> +                    $locale->mergeLocale( $pluginLocale );
> +                }
> +
>                  $loadedLocales[$localeCode] = $locale;
>              }
>  			
> @@ -102,7 +96,7 @@
>  		 */
>  		function getPluginLocale( $pluginId, $localeCode = null )
>  		{
> -        	global $_plugins_loadedLocales;
> +        	global $_plugins_loadedLocales;        	
>
>          	if( $localeCode == null ) {
>              	$config =& Config::getConfig();
>
> Modified: plog/branches/plog-1.0.1/class/plugin/pluginbase.class.php
> ===================================================================
> ---  
> plog/branches/plog-1.0.1/class/plugin/pluginbase.class.php	2005-04-10  
> 15:39:27 UTC (rev 1797)
> +++  
> plog/branches/plog-1.0.1/class/plugin/pluginbase.class.php	2005-04-10  
> 19:27:59 UTC (rev 1798)
> @@ -324,17 +324,16 @@
>  		}
>  		
>  		/**
> -		 * returns the list of supported locales by this plugin, or
an  
> empty array if the plugin
> -		 * does not define any array.
> +		 * returns true whether the plugin has the given locale
>  		 *
> -		 * @return Array
> +		 * @param localeCode the locale that we'd like to check
> +		 * @return whether the plugin provides the requested locale
>  		 */
> -		function getSupportedLocales()
> +		function hasLocale( $localeCode )
>  		{
> -			if( !is_array( $this->locales ))
> -				return Array();
> -			else
> -				return $this->locales;
> +		  $path =  
> "plugins/".$this->getId()."/locale/locale_".$localeCode.".php";
> +		
> +		  return( File::isReadable( $path ));
>  		}
>      }
>  ?>
>
> Modified: plog/branches/plog-1.0.1/class/plugin/pluginmanager.class.php
> ===================================================================
> ---  
> plog/branches/plog-1.0.1/class/plugin/pluginmanager.class.php	2005-04 
> -10 15:39:27 UTC (rev 1797)
> +++  
> plog/branches/plog-1.0.1/class/plugin/pluginmanager.class.php	2005-04 
> -10 19:27:59 UTC (rev 1798)
> @@ -78,6 +78,11 @@
>  			if( $this->_pluginList == "" )
>  				$this->_pluginList = Array();
>          }
> +
> +        function getPluginList()
> +        {
> +            return( $this->_pluginList );
> +        }
>
>          /**
>           * Sets the blog info
> @@ -162,11 +167,8 @@
>  						$className =
"Plugin".$plugin;
>  						include_once(
$pluginFullPath );
>  						$classInstance = new
$className();
> -						$name =
$classInstance->getId();
> -						$supportedLocales =
$classInstance->getSupportedLocales();
> -                   		foreach( $supportedLocales as $locale ) {
> -
$this->_loadPluginLocale( $classInstance->getId(), $locale );
> -						}
> +						$name =
$classInstance->getId();						
> +
>
$classInstance->setPluginFolder(  
> PLOG_CLASS_PATH.$pluginFile."/" );
>  						
>  						// tell the resource loader
that it should try to load actions  
> from this folder
> @@ -339,5 +341,18 @@
>
>              return $events;
>          }
> +
> +        /**
> +         * returns true if the plugin provides the requested locale
> +         *
> +         * @param pluginId The plugin identifier that we're like to  
> check
> +         * @param localeCode the locale code
> +         * @return True if the plugin has this locale or false  
> otherwise
> +         * @static
> +         */
> +        function pluginHasLocale( $pluginId, $localeCode )
> +        {
> +            return( File::isReadable(  
> "plugins/$pluginId/locale/locale_{$localeCode}.php" ));
> +        }
>      }
>  ?>
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.plogworld.net
> http://devel.plogworld.net/mailman/listinfo/plog-svn
>

_______________________________________________
pLog-svn mailing list
pLog-svn at devel.plogworld.net
http://devel.plogworld.net/mailman/listinfo/plog-svn




More information about the pLog-svn mailing list