Skip to content

Commit

Permalink
Bug #10221 Easier language selection
Browse files Browse the repository at this point in the history
added addTranslation($locale) method as per suggestions added to the bug report
above.


git-svn-id: http://svn.php.net/repository/pear/packages/Date_Holidays/trunk@274429 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
kenguest committed Jan 24, 2009
1 parent bd03acf commit 3ac7e87
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions Holidays/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,72 @@ function addDriver($driver)
{
}

/**
* addTranslation
*
* Search for installed language files appropriate for the specified
* locale and add them to the driver
*
* @param string $locale locale setting to be used
*
* @access public
* @return boolean true on success, otherwise false
*/
function addTranslation($locale)
{
$data_dir = "@DATA-DIR@";
$bestLocale = $this->_findBestLocale($locale);
$name = get_class($this);
$parts = explode("_", $name);
$drivername = $parts[3];
$matches = array();
$loaded = false;

$stubdir = $data_dir . "/Date_Holidays_{$drivername}/lang/{$drivername}/";
if (! is_dir($stubdir)) {
$stubdir = $data_dir . "/Date_Holidays/lang/";
}
if (is_dir($stubdir)) {
if ($dh = opendir($stubdir)) {
while (($file = readdir($dh)) !== false) {
if (strlen($locale) == 5) {
if (((strncasecmp($file, $bestLocale, 5) == 0))
|| (strncasecmp($file, $locale, 5) == 0)
) {
array_push($matches, $file);
}
}
if (strlen($locale) == 2) {
if (((strncasecmp($file, $bestLocale, 2) == 0))
|| (strncasecmp($file, $locale, 2) == 0)
) {
array_push($matches, $file);
}
}
}
closedir($dh);
$forget = array();
sort($matches);
foreach ($matches as $am) {
if (strpos($am, ".ser") !== false) {
$this->addCompiledTranslationFile($stubdir . $am, $locale);
$loaded = true;
array_push($forget, basename($am, ".ser") . ".xml");
} else {
if (!in_array($am, $forget)) {
$this->addTranslationFile(
$stubdir . $am,
str_replace(".xml", "", $am)
);
$loaded = true;
}
}
}
}
}
return $loaded;
}

/**
* Remove a driver component
*
Expand Down Expand Up @@ -940,6 +1006,10 @@ function addTranslationFile($file, $locale)
}

$content = $unserializer->getUnserializedData();
if (PEAR::isError($content)) {
return Date_Holidays::raiseError($content->getCode(),
$content->getMessage());
}
return $this->_addTranslationData($content, $locale);
}

Expand Down

0 comments on commit 3ac7e87

Please sign in to comment.