import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
@ -67,11 +67,14 @@ abstract class Zend_Translate_Adapter {
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = array(
|
||||
'clear' => false,
|
||||
'scan' => null,
|
||||
'locale' => 'auto',
|
||||
'ignore' => '.',
|
||||
'disableNotices' => false,
|
||||
'clear' => false,
|
||||
'disableNotices' => false,
|
||||
'ignore' => '.',
|
||||
'locale' => 'auto',
|
||||
'log' => null,
|
||||
'logMessage' => "Untranslated message within '%locale%': %message%",
|
||||
'logUntranslated' => false,
|
||||
'scan' => null
|
||||
);
|
||||
|
||||
/**
|
||||
@ -94,7 +97,8 @@ abstract class Zend_Translate_Adapter {
|
||||
{
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
if ($result = self::$_cache->load($id)) {
|
||||
$result = self::$_cache->load($id);
|
||||
if ($result) {
|
||||
$this->_options = unserialize($result);
|
||||
}
|
||||
}
|
||||
@ -106,7 +110,9 @@ abstract class Zend_Translate_Adapter {
|
||||
}
|
||||
|
||||
$this->addTranslation($data, $locale, $options);
|
||||
$this->setLocale($locale);
|
||||
if ($this->getLocale() !== (string) $locale) {
|
||||
$this->setLocale($locale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,12 +131,19 @@ abstract class Zend_Translate_Adapter {
|
||||
*/
|
||||
public function addTranslation($data, $locale = null, array $options = array())
|
||||
{
|
||||
$locale = $this->_getRegistryLocale($locale);
|
||||
try {
|
||||
$locale = Zend_Locale::findLocale($locale);
|
||||
} catch (Zend_Locale_Exception $e) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception("The given Language '{$locale}' does not exist");
|
||||
}
|
||||
|
||||
$originate = (string) $locale;
|
||||
|
||||
$this->setOptions($options);
|
||||
if (is_string($data) and is_dir($data)) {
|
||||
$prev = '';
|
||||
$data = realpath($data);
|
||||
$prev = '';
|
||||
foreach (new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($data, RecursiveDirectoryIterator::KEY_AS_PATHNAME),
|
||||
RecursiveIteratorIterator::SELF_FIRST) as $directory => $info) {
|
||||
@ -157,7 +170,7 @@ abstract class Zend_Translate_Adapter {
|
||||
if (Zend_Locale::isLocale((string) $filename, true, false)) {
|
||||
$locale = (string) $filename;
|
||||
} else {
|
||||
$parts = explode('.', $filename);
|
||||
$parts = explode('.', $file);
|
||||
$parts2 = array();
|
||||
foreach($parts as $token) {
|
||||
$parts2 += explode('_', $token);
|
||||
@ -197,7 +210,7 @@ abstract class Zend_Translate_Adapter {
|
||||
}
|
||||
}
|
||||
|
||||
if ((isset($this->_translate[$originate]) === true) and (count($this->_translate[$originate]) > 0)) {
|
||||
if ((isset($this->_translate[$originate]) === true) and (count($this->_translate[$originate]) > 0) and ($originate !== (string) $locale)) {
|
||||
$this->setLocale($originate);
|
||||
}
|
||||
|
||||
@ -213,15 +226,28 @@ abstract class Zend_Translate_Adapter {
|
||||
*/
|
||||
public function setOptions(array $options = array())
|
||||
{
|
||||
$change = false;
|
||||
$locale = null;
|
||||
foreach ($options as $key => $option) {
|
||||
if ($key == "locale") {
|
||||
$this->setLocale($option);
|
||||
} else {
|
||||
if ($key == 'locale') {
|
||||
$locale = $option;
|
||||
} else if ((isset($this->_options[$key]) and ($this->_options[$key] != $option)) or
|
||||
!isset($this->_options[$key])) {
|
||||
if (($key == 'log') && !($option instanceof Zend_Log)) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Instance of Zend_Log expected for option log');
|
||||
}
|
||||
|
||||
$this->_options[$key] = $option;
|
||||
$change = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset(self::$_cache)) {
|
||||
if ($locale !== null) {
|
||||
$this->setLocale($option);
|
||||
}
|
||||
|
||||
if (isset(self::$_cache) and ($change == true)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
self::$_cache->save( serialize($this->_options), $id);
|
||||
}
|
||||
@ -241,10 +267,11 @@ abstract class Zend_Translate_Adapter {
|
||||
if ($optionKey === null) {
|
||||
return $this->_options;
|
||||
}
|
||||
$optionKey = strtolower($optionKey);
|
||||
|
||||
if (isset($this->_options[$optionKey]) === true) {
|
||||
return $this->_options[$optionKey];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -267,33 +294,28 @@ abstract class Zend_Translate_Adapter {
|
||||
*/
|
||||
public function setLocale($locale)
|
||||
{
|
||||
$locale = $this->_getRegistryLocale($locale);
|
||||
if (($locale === "auto") or ($locale === null)) {
|
||||
$this->_automatic = true;
|
||||
} else {
|
||||
$this->_automatic = false;
|
||||
}
|
||||
|
||||
if (!Zend_Locale::isLocale($locale, true, false)) {
|
||||
if (!Zend_Locale::isLocale($locale, false, false)) {
|
||||
/**
|
||||
* @see Zend_Translate_Exception
|
||||
*/
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception("The given Language ({$locale }) does not exist");
|
||||
}
|
||||
|
||||
$locale = new Zend_Locale($locale);
|
||||
try {
|
||||
$locale = Zend_Locale::findLocale($locale);
|
||||
} catch (Zend_Locale_Exception $e) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception("The given Language ({$locale}) does not exist");
|
||||
}
|
||||
|
||||
$locale = (string) $locale;
|
||||
if (!isset($this->_translate[$locale])) {
|
||||
$temp = explode('_', $locale);
|
||||
if (!isset($this->_translate[$temp[0]]) and !isset($this->_translate[$locale])) {
|
||||
// Should we suppress notices ?
|
||||
if ($this->_options['disableNotices'] === false) {
|
||||
// throwing a notice due to possible problems on locale setting
|
||||
trigger_error("The language '{$locale}' has to be added before it can be used.", E_USER_NOTICE);
|
||||
if (!$this->_options['disableNotices']) {
|
||||
if ($this->_options['log']) {
|
||||
$this->_options['log']->notice("The language '{$locale}' has to be added before it can be used.");
|
||||
} else {
|
||||
trigger_error("The language '{$locale}' has to be added before it can be used.", E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -301,18 +323,22 @@ abstract class Zend_Translate_Adapter {
|
||||
}
|
||||
|
||||
if (empty($this->_translate[$locale])) {
|
||||
// Should we suppress notices ?
|
||||
if ($this->_options['disableNotices'] === false) {
|
||||
// throwing a notice due to possible problems on locale setting
|
||||
trigger_error("No translation for the language '{$locale}' available.", E_USER_NOTICE);
|
||||
if (!$this->_options['disableNotices']) {
|
||||
if ($this->_options['log']) {
|
||||
$this->_options['log']->notice("No translation for the language '{$locale}' available.");
|
||||
} else {
|
||||
trigger_error("No translation for the language '{$locale}' available.", E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_options['locale'] = $locale;
|
||||
if ($this->_options['locale'] != $locale) {
|
||||
$this->_options['locale'] = $locale;
|
||||
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
self::$_cache->save( serialize($this->_options), $id);
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
self::$_cache->save( serialize($this->_options), $id);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -392,7 +418,7 @@ abstract class Zend_Translate_Adapter {
|
||||
* @param mixed $data
|
||||
* @param string|Zend_Locale $locale
|
||||
* @param array $options (optional)
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function _loadTranslationData($data, $locale, array $options = array());
|
||||
|
||||
@ -413,33 +439,42 @@ abstract class Zend_Translate_Adapter {
|
||||
*/
|
||||
private function _addTranslationData($data, $locale, array $options = array())
|
||||
{
|
||||
if (!Zend_Locale::isLocale($locale, true, false)) {
|
||||
if (!Zend_Locale::isLocale($locale, false, false)) {
|
||||
/**
|
||||
* @see Zend_Translate_Exception
|
||||
*/
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception("The given Language ({$locale}) does not exist");
|
||||
}
|
||||
$locale = new Zend_Locale($locale);
|
||||
try {
|
||||
$locale = Zend_Locale::findLocale($locale);
|
||||
} catch (Zend_Locale_Exception $e) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception("The given Language '{$locale}' does not exist");
|
||||
}
|
||||
|
||||
$locale = (string) $locale;
|
||||
if (isset($this->_translate[$locale]) === false) {
|
||||
if ($options['clear'] || !isset($this->_translate[$locale])) {
|
||||
$this->_translate[$locale] = array();
|
||||
}
|
||||
|
||||
$read = true;
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $locale . '_' . $this->toString();
|
||||
if ($result = self::$_cache->load($id)) {
|
||||
$this->_translate[$locale] = unserialize($result);
|
||||
$id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $this->toString();
|
||||
$result = self::$_cache->load($id);
|
||||
if ($result) {
|
||||
$temp = unserialize($result);
|
||||
$read = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($read) {
|
||||
$this->_loadTranslationData($data, $locale, $options);
|
||||
$temp = $this->_loadTranslationData($data, $locale, $options);
|
||||
}
|
||||
|
||||
if (empty($temp)) {
|
||||
$temp = array();
|
||||
}
|
||||
|
||||
$keys = array_keys($temp);
|
||||
foreach($keys as $key) {
|
||||
if (!isset($this->_translate[$key])) {
|
||||
$this->_translate[$key] = array();
|
||||
}
|
||||
|
||||
$this->_translate[$key] = $this->_translate[$key] + $temp[$key];
|
||||
}
|
||||
|
||||
if ($this->_automatic === true) {
|
||||
@ -447,7 +482,7 @@ abstract class Zend_Translate_Adapter {
|
||||
$browser = $find->getEnvironment() + $find->getBrowser();
|
||||
arsort($browser);
|
||||
foreach($browser as $language => $quality) {
|
||||
if (isset($this->_translate[$language]) === true) {
|
||||
if (isset($this->_translate[$language])) {
|
||||
$this->_options['locale'] = $language;
|
||||
break;
|
||||
}
|
||||
@ -455,8 +490,8 @@ abstract class Zend_Translate_Adapter {
|
||||
}
|
||||
|
||||
if (($read) and (isset(self::$_cache))) {
|
||||
$id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $locale . '_' . $this->toString();
|
||||
self::$_cache->save( serialize($this->_translate[$locale]), $id);
|
||||
$id = 'Zend_Translate_' . preg_replace('/[^a-zA-Z0-9_]/', '_', $data) . '_' . $this->toString();
|
||||
self::$_cache->save( serialize($temp), $id);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -477,32 +512,53 @@ abstract class Zend_Translate_Adapter {
|
||||
if ($locale === null) {
|
||||
$locale = $this->_options['locale'];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
$locale = new Zend_Locale($locale);
|
||||
}
|
||||
|
||||
$locale = (string) $locale;
|
||||
if (isset($this->_translate[$locale][$messageId]) === true) {
|
||||
if (isset($this->_translate[$locale][$messageId])) {
|
||||
// return original translation
|
||||
return $this->_translate[$locale][$messageId];
|
||||
} 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]) === true) {
|
||||
if (isset($this->_translate[$locale][$messageId])) {
|
||||
// return regionless translation (en_US -> en)
|
||||
return $this->_translate[$locale][$messageId];
|
||||
}
|
||||
}
|
||||
|
||||
// no translation found, return original
|
||||
$this->_log($messageId, $locale);
|
||||
return $messageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message when the log option is set
|
||||
*
|
||||
* @param string $message Message to log
|
||||
* @param String $locale Locale to log
|
||||
*/
|
||||
protected function _log($message, $locale) {
|
||||
if ($this->_options['logUntranslated']) {
|
||||
$message = str_replace('%message%', $message, $this->_options['logMessage']);
|
||||
$message = str_replace('%locale%', $locale, $message);
|
||||
if ($this->_options['log']) {
|
||||
$this->_options['log']->notice($message);
|
||||
} else {
|
||||
trigger_error($message, E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given string
|
||||
* returns the translation
|
||||
@ -543,6 +599,7 @@ abstract class Zend_Translate_Adapter {
|
||||
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 false;
|
||||
}
|
||||
|
||||
@ -564,6 +621,7 @@ abstract class Zend_Translate_Adapter {
|
||||
}
|
||||
|
||||
// No translation found, return original
|
||||
$this->_log($messageId, $locale);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -621,28 +679,6 @@ abstract class Zend_Translate_Adapter {
|
||||
self::$_cache->clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluates the locale from registry or auto
|
||||
*
|
||||
* @param string|Zend_Locale $locale
|
||||
* @return string
|
||||
*/
|
||||
private function _getRegistryLocale($locale)
|
||||
{
|
||||
if (empty($locale)) {
|
||||
require_once 'Zend/Registry.php';
|
||||
if (Zend_Registry::isRegistered('Zend_Locale') === true) {
|
||||
$locale = Zend_Registry::get('Zend_Locale');
|
||||
}
|
||||
}
|
||||
|
||||
if ($locale === null) {
|
||||
$locale = new Zend_Locale();
|
||||
}
|
||||
|
||||
return $locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapter name
|
||||
*
|
||||
|
@ -33,7 +33,10 @@ require_once 'Zend/Translate/Adapter.php';
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Translate_Adapter_Array extends Zend_Translate_Adapter {
|
||||
class Zend_Translate_Adapter_Array extends Zend_Translate_Adapter
|
||||
{
|
||||
private $_data = array();
|
||||
|
||||
/**
|
||||
* Generates the adapter
|
||||
*
|
||||
@ -54,9 +57,11 @@ class Zend_Translate_Adapter_Array extends Zend_Translate_Adapter {
|
||||
* @param string $locale Locale/Language to add data for, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $options OPTIONAL Options to use
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadTranslationData($data, $locale, array $options = array())
|
||||
{
|
||||
$this->_data = array();
|
||||
if (!is_array($data)) {
|
||||
if (file_exists($data)) {
|
||||
ob_start();
|
||||
@ -69,12 +74,12 @@ class Zend_Translate_Adapter_Array extends Zend_Translate_Adapter {
|
||||
throw new Zend_Translate_Exception("Error including array or file '".$data."'");
|
||||
}
|
||||
|
||||
$options = $options + $this->_options;
|
||||
if (($options['clear'] == true) || !isset($this->_translate[$locale])) {
|
||||
$this->_translate[$locale] = array();
|
||||
if (!isset($this->_data[$locale])) {
|
||||
$this->_data[$locale] = array();
|
||||
}
|
||||
|
||||
$this->_translate[$locale] = $data + $this->_translate[$locale];
|
||||
$this->_data[$locale] = $data + $this->_data[$locale];
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,7 +33,9 @@ require_once 'Zend/Translate/Adapter.php';
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Translate_Adapter_Csv extends Zend_Translate_Adapter {
|
||||
class Zend_Translate_Adapter_Csv extends Zend_Translate_Adapter
|
||||
{
|
||||
private $_data = array();
|
||||
|
||||
/**
|
||||
* Generates the adapter
|
||||
@ -58,15 +60,12 @@ class Zend_Translate_Adapter_Csv extends Zend_Translate_Adapter {
|
||||
* @param string $locale Locale/Language to add data for, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $option OPTIONAL Options to use
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $options + $this->_options;
|
||||
|
||||
if ($options['clear'] || !isset($this->_translate[$locale])) {
|
||||
$this->_translate[$locale] = array();
|
||||
}
|
||||
|
||||
$this->_data = array();
|
||||
$options = $options + $this->_options;
|
||||
$this->_file = @fopen($filename, 'rb');
|
||||
if (!$this->_file) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
@ -82,8 +81,10 @@ class Zend_Translate_Adapter_Csv extends Zend_Translate_Adapter {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->_translate[$locale][$data[0]] = $data[1];
|
||||
$this->_data[$locale][$data[0]] = $data[1];
|
||||
}
|
||||
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,6 +36,7 @@ class Zend_Translate_Adapter_Gettext extends Zend_Translate_Adapter {
|
||||
private $_bigEndian = false;
|
||||
private $_file = false;
|
||||
private $_adapterInfo = array();
|
||||
private $_data = array();
|
||||
|
||||
/**
|
||||
* Generates the adapter
|
||||
@ -72,17 +73,13 @@ class Zend_Translate_Adapter_Gettext extends Zend_Translate_Adapter {
|
||||
* see Zend_Locale for more information
|
||||
* @param array $option OPTIONAL Options to use
|
||||
* @throws Zend_Translation_Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$this->_data = array();
|
||||
$this->_bigEndian = false;
|
||||
$options = $options + $this->_options;
|
||||
|
||||
if ($options['clear'] || !isset($this->_translate[$locale])) {
|
||||
$this->_translate[$locale] = array();
|
||||
}
|
||||
|
||||
$this->_file = @fopen($filename, 'rb');
|
||||
$this->_file = @fopen($filename, 'rb');
|
||||
if (!$this->_file) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.');
|
||||
@ -133,18 +130,19 @@ class Zend_Translate_Adapter_Gettext extends Zend_Translate_Adapter {
|
||||
|
||||
if ($transtemp[$count * 2 + 1] != 0) {
|
||||
fseek($this->_file, $transtemp[$count * 2 + 2]);
|
||||
$this->_translate[$locale][$original] = fread($this->_file, $transtemp[$count * 2 + 1]);
|
||||
$this->_data[$locale][$original] = fread($this->_file, $transtemp[$count * 2 + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_translate[$locale][''] = trim($this->_translate[$locale]['']);
|
||||
if (empty($this->_translate[$locale][''])) {
|
||||
$this->_data[$locale][''] = trim($this->_data[$locale]['']);
|
||||
if (empty($this->_data[$locale][''])) {
|
||||
$this->_adapterInfo[$filename] = 'No adapter information available';
|
||||
} else {
|
||||
$this->_adapterInfo[$filename] = $this->_translate[$locale][''];
|
||||
$this->_adapterInfo[$filename] = $this->_data[$locale][''];
|
||||
}
|
||||
|
||||
unset($this->_translate[$locale]['']);
|
||||
unset($this->_data[$locale]['']);
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,6 +33,8 @@ require_once 'Zend/Translate/Adapter.php';
|
||||
*/
|
||||
class Zend_Translate_Adapter_Ini extends Zend_Translate_Adapter
|
||||
{
|
||||
private $_data = array();
|
||||
|
||||
/**
|
||||
* Generates the adapter
|
||||
*
|
||||
@ -53,20 +55,24 @@ class Zend_Translate_Adapter_Ini extends Zend_Translate_Adapter
|
||||
* @param string $locale Locale/Language to add data for, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $options OPTIONAL Options to use
|
||||
* @throws Zend_Translate_Exception Ini file not found
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadTranslationData($data, $locale, array $options = array())
|
||||
{
|
||||
$this->_data = array();
|
||||
if (!file_exists($data)) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception("Ini file '".$data."' not found");
|
||||
}
|
||||
$inidata = parse_ini_file($data, false);
|
||||
|
||||
$options = array_merge($this->_options, $options);
|
||||
if (($options['clear'] == true) || !isset($this->_translate[$locale])) {
|
||||
$this->_translate[$locale] = array();
|
||||
$inidata = parse_ini_file($data, false);
|
||||
if (!isset($this->_data[$locale])) {
|
||||
$this->_data[$locale] = array();
|
||||
}
|
||||
$this->_translate[$locale] = array_merge($this->_translate[$locale], $inidata);
|
||||
|
||||
$this->_data[$locale] = array_merge($this->_data[$locale], $inidata);
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,6 +44,7 @@ class Zend_Translate_Adapter_Qt extends Zend_Translate_Adapter {
|
||||
private $_tcontent = null;
|
||||
private $_stag = false;
|
||||
private $_ttag = true;
|
||||
private $_data = array();
|
||||
|
||||
/**
|
||||
* Generates the Qt adapter
|
||||
@ -68,15 +69,11 @@ class Zend_Translate_Adapter_Qt extends Zend_Translate_Adapter {
|
||||
* @param string $filename QT file to add, full path must be given for access
|
||||
* @param array $option OPTIONAL Options to use
|
||||
* @throws Zend_Translation_Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $options + $this->_options;
|
||||
|
||||
if ($options['clear'] || !isset($this->_translate[$locale])) {
|
||||
$this->_translate[$locale] = array();
|
||||
}
|
||||
|
||||
$this->_data = array();
|
||||
if (!is_readable($filename)) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
|
||||
@ -99,6 +96,8 @@ class Zend_Translate_Adapter_Qt extends Zend_Translate_Adapter {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception($ex);
|
||||
}
|
||||
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
private function _startElement($file, $name, $attrib)
|
||||
@ -131,8 +130,8 @@ class Zend_Translate_Adapter_Qt extends Zend_Translate_Adapter {
|
||||
|
||||
case 'translation':
|
||||
if (!empty($this->_scontent) and !empty($this->_tcontent) or
|
||||
(isset($this->_translate[$this->_target][$this->_scontent]) === false)) {
|
||||
$this->_translate[$this->_target][$this->_scontent] = $this->_tcontent;
|
||||
(isset($this->_data[$this->_target][$this->_scontent]) === false)) {
|
||||
$this->_data[$this->_target][$this->_scontent] = $this->_tcontent;
|
||||
}
|
||||
$this->_ttag = false;
|
||||
break;
|
||||
|
@ -41,6 +41,7 @@ class Zend_Translate_Adapter_Tbx extends Zend_Translate_Adapter {
|
||||
private $_termentry = null;
|
||||
private $_content = null;
|
||||
private $_term = null;
|
||||
private $_data = array();
|
||||
|
||||
/**
|
||||
* Generates the tbx adapter
|
||||
@ -56,7 +57,6 @@ class Zend_Translate_Adapter_Tbx extends Zend_Translate_Adapter {
|
||||
parent::__construct($data, $locale, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load translation data (TBX file reader)
|
||||
*
|
||||
@ -65,15 +65,11 @@ class Zend_Translate_Adapter_Tbx extends Zend_Translate_Adapter {
|
||||
* the source file
|
||||
* @param array $option OPTIONAL Options to use
|
||||
* @throws Zend_Translation_Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $options + $this->_options;
|
||||
|
||||
if ($options['clear']) {
|
||||
$this->_translate = array();
|
||||
}
|
||||
|
||||
$this->_data = array();
|
||||
if (!is_readable($filename)) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
|
||||
@ -94,6 +90,8 @@ class Zend_Translate_Adapter_Tbx extends Zend_Translate_Adapter {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception($ex);
|
||||
}
|
||||
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
private function _startElement($file, $name, $attrib)
|
||||
@ -112,8 +110,8 @@ class Zend_Translate_Adapter_Tbx extends Zend_Translate_Adapter {
|
||||
case 'langset':
|
||||
if (isset($attrib['xml:lang']) === true) {
|
||||
$this->_langset = $attrib['xml:lang'];
|
||||
if (isset($this->_translate[$this->_langset]) === false) {
|
||||
$this->_translate[$this->_langset] = array();
|
||||
if (isset($this->_data[$this->_langset]) === false) {
|
||||
$this->_data[$this->_langset] = array();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -141,8 +139,8 @@ class Zend_Translate_Adapter_Tbx extends Zend_Translate_Adapter {
|
||||
if (empty($this->_termentry)) {
|
||||
$this->_termentry = $this->_content;
|
||||
}
|
||||
if (!empty($this->_content) or (isset($this->_translate[$this->_langset][$this->_termentry]) === false)) {
|
||||
$this->_translate[$this->_langset][$this->_termentry] = $this->_content;
|
||||
if (!empty($this->_content) or (isset($this->_data[$this->_langset][$this->_termentry]) === false)) {
|
||||
$this->_data[$this->_langset][$this->_termentry] = $this->_content;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -35,12 +35,12 @@ require_once 'Zend/Translate/Adapter.php';
|
||||
*/
|
||||
class Zend_Translate_Adapter_Tmx extends Zend_Translate_Adapter {
|
||||
// Internal variables
|
||||
private $_file = false;
|
||||
private $_cleared = array();
|
||||
private $_tu = null;
|
||||
private $_tuv = null;
|
||||
private $_seg = null;
|
||||
private $_content = null;
|
||||
private $_file = false;
|
||||
private $_tu = null;
|
||||
private $_tuv = null;
|
||||
private $_seg = null;
|
||||
private $_content = null;
|
||||
private $_data = array();
|
||||
|
||||
/**
|
||||
* Generates the tmx adapter
|
||||
@ -65,15 +65,11 @@ class Zend_Translate_Adapter_Tmx extends Zend_Translate_Adapter {
|
||||
* the source file
|
||||
* @param array $option OPTIONAL Options to use
|
||||
* @throws Zend_Translation_Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $this->_options + $options;
|
||||
|
||||
if ($options['clear']) {
|
||||
$this->_translate = array();
|
||||
}
|
||||
|
||||
$this->_data = array();
|
||||
if (!is_readable($filename)) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
|
||||
@ -94,6 +90,8 @@ class Zend_Translate_Adapter_Tmx extends Zend_Translate_Adapter {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception($ex);
|
||||
}
|
||||
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
private function _startElement($file, $name, $attrib)
|
||||
@ -114,8 +112,8 @@ class Zend_Translate_Adapter_Tmx extends Zend_Translate_Adapter {
|
||||
case 'tuv':
|
||||
if (isset($attrib['xml:lang']) === true) {
|
||||
$this->_tuv = $attrib['xml:lang'];
|
||||
if (isset($this->_translate[$this->_tuv]) === false) {
|
||||
$this->_translate[$this->_tuv] = array();
|
||||
if (isset($this->_data[$this->_tuv]) === false) {
|
||||
$this->_data[$this->_tuv] = array();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -143,8 +141,8 @@ class Zend_Translate_Adapter_Tmx extends Zend_Translate_Adapter {
|
||||
break;
|
||||
case 'seg':
|
||||
$this->_seg = null;
|
||||
if (!empty($this->_content) or (isset($this->_translate[$this->_tuv][$this->_tu]) === false)) {
|
||||
$this->_translate[$this->_tuv][$this->_tu] = $this->_content;
|
||||
if (!empty($this->_content) or (!isset($this->_data[$this->_tuv][$this->_tu]))) {
|
||||
$this->_data[$this->_tuv][$this->_tu] = $this->_content;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -44,6 +44,7 @@ class Zend_Translate_Adapter_Xliff extends Zend_Translate_Adapter {
|
||||
private $_tcontent = null;
|
||||
private $_stag = false;
|
||||
private $_ttag = false;
|
||||
private $_data = array();
|
||||
|
||||
/**
|
||||
* Generates the xliff adapter
|
||||
@ -68,15 +69,11 @@ class Zend_Translate_Adapter_Xliff extends Zend_Translate_Adapter {
|
||||
* @param string $filename XLIFF file to add, full path must be given for access
|
||||
* @param array $option OPTIONAL Options to use
|
||||
* @throws Zend_Translation_Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $options + $this->_options;
|
||||
|
||||
if ($options['clear']) {
|
||||
$this->_translate = array();
|
||||
}
|
||||
|
||||
$this->_data = array();
|
||||
if (!is_readable($filename)) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
|
||||
@ -98,6 +95,8 @@ class Zend_Translate_Adapter_Xliff extends Zend_Translate_Adapter {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception($ex);
|
||||
}
|
||||
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
private function _startElement($file, $name, $attrib)
|
||||
@ -122,8 +121,14 @@ class Zend_Translate_Adapter_Xliff extends Zend_Translate_Adapter {
|
||||
$this->_target = $attrib['target-language'];
|
||||
}
|
||||
|
||||
$this->_translate[$this->_source] = array();
|
||||
$this->_translate[$this->_target] = array();
|
||||
if (!isset($this->_data[$this->_source])) {
|
||||
$this->_data[$this->_source] = array();
|
||||
}
|
||||
|
||||
if (!isset($this->_data[$this->_target])) {
|
||||
$this->_data[$this->_target] = array();
|
||||
}
|
||||
|
||||
break;
|
||||
case 'trans-unit':
|
||||
$this->_transunit = true;
|
||||
@ -163,15 +168,15 @@ class Zend_Translate_Adapter_Xliff extends Zend_Translate_Adapter {
|
||||
break;
|
||||
case 'source':
|
||||
if (!empty($this->_scontent) and !empty($this->_tcontent) or
|
||||
(isset($this->_translate[$this->_source][$this->_scontent]) === false)) {
|
||||
$this->_translate[$this->_source][$this->_scontent] = $this->_scontent;
|
||||
(isset($this->_data[$this->_source][$this->_scontent]) === false)) {
|
||||
$this->_data[$this->_source][$this->_scontent] = $this->_scontent;
|
||||
}
|
||||
$this->_stag = false;
|
||||
break;
|
||||
case 'target':
|
||||
if (!empty($this->_scontent) and !empty($this->_tcontent) or
|
||||
(isset($this->_translate[$this->_source][$this->_scontent]) === false)) {
|
||||
$this->_translate[$this->_target][$this->_scontent] = $this->_tcontent;
|
||||
(isset($this->_data[$this->_source][$this->_scontent]) === false)) {
|
||||
$this->_data[$this->_target][$this->_scontent] = $this->_tcontent;
|
||||
}
|
||||
$this->_ttag = false;
|
||||
break;
|
||||
|
@ -40,6 +40,7 @@ class Zend_Translate_Adapter_XmlTm extends Zend_Translate_Adapter {
|
||||
private $_lang = null;
|
||||
private $_content = null;
|
||||
private $_tag = null;
|
||||
private $_data = array();
|
||||
|
||||
/**
|
||||
* Generates the xmltm adapter
|
||||
@ -64,22 +65,18 @@ class Zend_Translate_Adapter_XmlTm extends Zend_Translate_Adapter {
|
||||
* @param string $filename XMLTM file to add, full path must be given for access
|
||||
* @param array $option OPTIONAL Options to use
|
||||
* @throws Zend_Translation_Exception
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $options + $this->_options;
|
||||
$this->_data = array();
|
||||
$this->_lang = $locale;
|
||||
|
||||
if ($options['clear'] || !isset($this->_translate[$locale])) {
|
||||
$this->_translate[$locale] = array();
|
||||
}
|
||||
|
||||
if (!is_readable($filename)) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
|
||||
}
|
||||
|
||||
$encoding = $this->_findEncoding($filename);
|
||||
$encoding = $this->_findEncoding($filename);
|
||||
$this->_file = xml_parser_create($encoding);
|
||||
xml_set_object($this->_file, $this);
|
||||
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
|
||||
@ -94,6 +91,8 @@ class Zend_Translate_Adapter_XmlTm extends Zend_Translate_Adapter {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception($ex);
|
||||
}
|
||||
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
private function _startElement($file, $name, $attrib)
|
||||
@ -113,8 +112,8 @@ class Zend_Translate_Adapter_XmlTm extends Zend_Translate_Adapter {
|
||||
switch (strtolower($name)) {
|
||||
case 'tm:tu':
|
||||
if (!empty($this->_tag) and !empty($this->_content) or
|
||||
(isset($this->_translate[$this->_lang][$this->_tag]) === false)) {
|
||||
$this->_translate[$this->_lang][$this->_tag] = $this->_content;
|
||||
(isset($this->_data[$this->_lang][$this->_tag]) === false)) {
|
||||
$this->_data[$this->_lang][$this->_tag] = $this->_content;
|
||||
}
|
||||
$this->_tag = null;
|
||||
$this->_content = null;
|
||||
|
Reference in New Issue
Block a user