import v1.1.0_RC2 | 2009-09-20
This commit is contained in:
@ -15,9 +15,9 @@
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @subpackage Zend_Translate_Adapter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
|
||||
* @version $Id: Adapter.php 17761 2009-08-22 22:23:12Z thomas $
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -25,13 +25,18 @@
|
||||
*/
|
||||
require_once 'Zend/Locale.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Translate_Plural
|
||||
*/
|
||||
require_once 'Zend/Translate/Plural.php';
|
||||
|
||||
/**
|
||||
* Basic adapter class for each translation source adapter
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @subpackage Zend_Translate_Adapter
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Translate_Adapter {
|
||||
@ -244,12 +249,12 @@ abstract class Zend_Translate_Adapter {
|
||||
}
|
||||
|
||||
if ($locale !== null) {
|
||||
$this->setLocale($option);
|
||||
$this->setLocale($locale);
|
||||
}
|
||||
|
||||
if (isset(self::$_cache) and ($change == true)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
self::$_cache->save( serialize($this->_options), $id);
|
||||
self::$_cache->save( serialize($this->_options), $id, array('Zend_Translate'));
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -337,7 +342,7 @@ abstract class Zend_Translate_Adapter {
|
||||
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
self::$_cache->save( serialize($this->_options), $id);
|
||||
self::$_cache->save( serialize($this->_options), $id, array('Zend_Translate'));
|
||||
}
|
||||
}
|
||||
|
||||
@ -452,7 +457,7 @@ abstract class Zend_Translate_Adapter {
|
||||
|
||||
$read = true;
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $this->toString();
|
||||
$id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
|
||||
$result = self::$_cache->load($id);
|
||||
if ($result) {
|
||||
$temp = unserialize($result);
|
||||
@ -474,7 +479,7 @@ abstract class Zend_Translate_Adapter {
|
||||
$this->_translate[$key] = array();
|
||||
}
|
||||
|
||||
$this->_translate[$key] = $this->_translate[$key] + $temp[$key];
|
||||
$this->_translate[$key] = $temp[$key] + $this->_translate[$key];
|
||||
}
|
||||
|
||||
if ($this->_automatic === true) {
|
||||
@ -490,8 +495,8 @@ abstract class Zend_Translate_Adapter {
|
||||
}
|
||||
|
||||
if (($read) and (isset(self::$_cache))) {
|
||||
$id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $this->toString();
|
||||
self::$_cache->save( serialize($temp), $id);
|
||||
$id = 'Zend_Translate_' . md5(serialize($data)) . '_' . $this->toString();
|
||||
self::$_cache->save( serialize($temp), $id, array('Zend_Translate'));
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -502,7 +507,7 @@ abstract class Zend_Translate_Adapter {
|
||||
* returns the translation
|
||||
*
|
||||
* @see Zend_Locale
|
||||
* @param string $messageId Translation string
|
||||
* @param string|array $messageId Translation string, or Array for plural translations
|
||||
* @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with
|
||||
* locale identifier, @see Zend_Locale for more information
|
||||
* @return string
|
||||
@ -513,11 +518,38 @@ abstract class Zend_Translate_Adapter {
|
||||
$locale = $this->_options['locale'];
|
||||
}
|
||||
|
||||
$plural = null;
|
||||
if (is_array($messageId)) {
|
||||
if (count($messageId) > 2) {
|
||||
$number = array_pop($messageId);
|
||||
if (!is_numeric($number)) {
|
||||
$plocale = $number;
|
||||
$number = array_pop($messageId);
|
||||
} else {
|
||||
$plocale = 'en';
|
||||
}
|
||||
|
||||
$plural = $messageId;
|
||||
$messageId = $messageId[0];
|
||||
} else {
|
||||
$messageId = $messageId[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (!Zend_Locale::isLocale($locale, true, false)) {
|
||||
if (!Zend_Locale::isLocale($locale, false, false)) {
|
||||
// language does not exist, return original string
|
||||
$this->_log($messageId, $locale);
|
||||
return $messageId;
|
||||
if ($plural === null) {
|
||||
return $messageId;
|
||||
}
|
||||
|
||||
$rule = Zend_Translate_Plural::getPlural($number, $plocale);
|
||||
if (!isset($plural[$rule])) {
|
||||
$rule = 0;
|
||||
}
|
||||
|
||||
return $plural[$rule];
|
||||
}
|
||||
|
||||
$locale = new Zend_Locale($locale);
|
||||
@ -526,19 +558,59 @@ abstract class Zend_Translate_Adapter {
|
||||
$locale = (string) $locale;
|
||||
if (isset($this->_translate[$locale][$messageId])) {
|
||||
// return original translation
|
||||
return $this->_translate[$locale][$messageId];
|
||||
if ($plural === null) {
|
||||
return $this->_translate[$locale][$messageId];
|
||||
}
|
||||
|
||||
$rule = Zend_Translate_Plural::getPlural($number, $locale);
|
||||
if (isset($this->_translate[$locale][$plural[0]][$rule])) {
|
||||
return $this->_translate[$locale][$plural[0]][$rule];
|
||||
}
|
||||
} else if (strlen($locale) != 2) {
|
||||
// faster than creating a new locale and separate the leading part
|
||||
$locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
|
||||
|
||||
if (isset($this->_translate[$locale][$messageId])) {
|
||||
// return regionless translation (en_US -> en)
|
||||
return $this->_translate[$locale][$messageId];
|
||||
if ($plural === null) {
|
||||
return $this->_translate[$locale][$messageId];
|
||||
}
|
||||
|
||||
$rule = Zend_Translate_Plural::getPlural($number, $locale);
|
||||
if (isset($this->_translate[$locale][$plural[0]][$rule])) {
|
||||
return $this->_translate[$locale][$plural[0]][$rule];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_log($messageId, $locale);
|
||||
return $messageId;
|
||||
if ($plural === null) {
|
||||
return $messageId;
|
||||
}
|
||||
|
||||
$rule = Zend_Translate_Plural::getPlural($number, $plocale);
|
||||
if (!isset($plural[$rule])) {
|
||||
$rule = 0;
|
||||
}
|
||||
|
||||
return $plural[$rule];
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given string using plural notations
|
||||
* Returns the translated string
|
||||
*
|
||||
* @see Zend_Locale
|
||||
* @param string $singular Singular translation string
|
||||
* @param string $plural Plural translation string
|
||||
* @param integer $number Number for detecting the correct plural
|
||||
* @param string|Zend_Locale $locale (Optional) Locale/Language to use, identical with
|
||||
* locale identifier, @see Zend_Locale for more information
|
||||
* @return string
|
||||
*/
|
||||
public function plural($singular, $plural, $number, $locale = null)
|
||||
{
|
||||
return $this->translate(array($singular, $plural, $number), $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -603,7 +675,7 @@ abstract class Zend_Translate_Adapter {
|
||||
return false;
|
||||
}
|
||||
|
||||
$locale = new Zend_Locale();
|
||||
$locale = new Zend_Locale($locale);
|
||||
}
|
||||
|
||||
$locale = (string) $locale;
|
||||
@ -676,7 +748,8 @@ abstract class Zend_Translate_Adapter {
|
||||
*/
|
||||
public static function clearCache()
|
||||
{
|
||||
self::$_cache->clean();
|
||||
require_once 'Zend/Cache.php';
|
||||
self::$_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('Zend_Translate'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user