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
Developer Resources:

Documentation: The OJS Technical Reference and the OJS API Reference are both available from the OJS Documentation page.

Git: You can access our public Git Repository here. Comprehensive Git usage instructions are available on the wiki.

Bugzilla: You can access our Bugzilla report tracker here.

Search: You can use our Google Custom Search to search across our main website, the support forum, and Bugzilla.

Questions and discussion are welcome, but if you have a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a technical support question, try the OJS Technical Support subforum.

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: 8445
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: 8445
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: 8445
Joined: Wed Aug 10, 2005 12:56 pm


Return to OJS Development

Who is online

Users browsing this forum: No registered users and 2 guests

cron