Skip to content

Commit

Permalink
Modules\Module: implement listLocales
Browse files Browse the repository at this point in the history
fixes #7054
  • Loading branch information
Thomas-Gelf committed Sep 2, 2014
1 parent e4687a6 commit 4cef333
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion library/Icinga/Application/Modules/Module.php
Expand Up @@ -708,12 +708,44 @@ protected function registerAutoloader()
*/
protected function registerLocales()
{
if (file_exists($this->localedir) && is_dir($this->localedir)) {
if ($this->hasLocales()) {
Translator::registerDomain($this->name, $this->localedir);
}
return $this;
}

/**
* return bool Whether this module has translations
*/
public function hasLocales()
{
return file_exists($this->localedir) && is_dir($this->localedir);
}

/**
* List all available locales
*
* return array Locale list
*/
public function listLocales()
{
$locales = array();
if (! $this->hasLocales()) {
return $locales;
}

$dh = opendir($this->localedir);
while (false !== ($file = readdir($dh))) {
$filename = $this->localedir . DIRECTORY_SEPARATOR . $file;
if (preg_match('/^[a-z]{2}_[A-Z]{2}$/', $file) && is_dir($filename)) {
$locales[] = $file;
}
}
closedir($dh);
sort($locales);
return $locales;
}

/**
* Register web integration
*
Expand Down

0 comments on commit 4cef333

Please sign in to comment.