OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



Getting the available locales for a plugin

OJS development discussion, enhancement requests, third-party patches and plug-ins.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
The Public Knowledge Project Support Forum is moving to http://forum.pkp.sfu.ca

This forum will be maintained permanently as an archived historical resource, but all new questions should be added to the new forum. Questions will no longer be monitored on this old forum after March 30, 2015.

Getting the available locales for a plugin

Postby christo » Thu Aug 16, 2007 1:44 am

Is there a function as part of the plugin class which enables you to get a list of all the available locales for that plugin? I have had a look around but dont think i found one...

something like:
Code: Select all
$myPlugin = &PluginRegistry::getPlugin('generic', 'MyPlugin');
$availableLocales = $myPlugin->getLocales();

would be useful..
christo
 
Posts: 22
Joined: Mon Jan 09, 2006 12:04 am
Location: Grahamstown, South Africa

Re: Getting the available locales for a plugin

Postby asmecher » Thu Aug 16, 2007 9:41 am

Hi Christo,

No function currently exists for this; I'd suggest using the glob or opendir functions to have a look at the locale directory's contents manually.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm

Re: Getting the available locales for a plugin

Postby christo » Thu Aug 16, 2007 1:41 pm

Hi Alec

Cool, just didnt want to re-invent the wheel. if i write such function for the plugin class, would it be worth including in the core? or should i rather just write it for my plugin?
christo
 
Posts: 22
Joined: Mon Jan 09, 2006 12:04 am
Location: Grahamstown, South Africa

Re: Getting the available locales for a plugin

Postby asmecher » Thu Aug 16, 2007 2:21 pm

Hi Christo,

This might be a good method to include in classes/plugin/Plugin.inc.php. Feel free to submit it and I'll review the code for inclusion in OJS 2.2.

Thanks,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm

Re: Getting the available locales for a plugin

Postby christo » Fri Aug 24, 2007 7:05 am

ok. I have written a little function for gettng the locales installed for a plugin. Here it is:

Code: Select all
       /**
    * Function to get all the available locales for a plugin
    *
    * @return string[] $locales
    */
   function getAvailableLocales(){
      $locales = array();
      $fullPath = $this->getTemplatePath().'locale'; //get the absolute url to the locale folder
      // get the relative url (glob appears only to like relative urls - or its is a windows issue with the path...
      $splitPath = split("plugins",$fullPath);
      $path =  'plugins'.$splitPath[1];
      //get the folders and remove the path except for the last bit (the locale folder)
      foreach (glob($path.'/*',GLOB_ONLYDIR) as $locale){
         $locale = ereg_replace($path.'/','',$locale);
         array_push($locales,$locale);
      }
      return $locales;
    }
christo
 
Posts: 22
Joined: Mon Jan 09, 2006 12:04 am
Location: Grahamstown, South Africa

Re: Getting the available locales for a plugin

Postby asmecher » Fri Aug 24, 2007 9:51 am

Hi Christo,

Excellent; I've added a Bugzilla entry to move this into the core codebase. See http://pkp.sfu.ca/bugzilla/show_bug.cgi?id=2981.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 10015
Joined: Wed Aug 10, 2005 12:56 pm


Return to OJS Development

Who is online

Users browsing this forum: No registered users and 1 guest