import v1.0.0-RC4 | 2009-05-20
This commit is contained in:
652
libs/Zend/Translate/Adapter.php
Normal file
652
libs/Zend/Translate/Adapter.php
Normal file
@ -0,0 +1,652 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @subpackage Zend_Translate_Adapter
|
||||
* @copyright Copyright (c) 2005-2008 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 $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Locale
|
||||
*/
|
||||
require_once 'Zend/Locale.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)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Translate_Adapter {
|
||||
/**
|
||||
* Shows if locale detection is in automatic level
|
||||
* @var boolean
|
||||
*/
|
||||
private $_automatic = true;
|
||||
|
||||
/**
|
||||
* Internal cache for all adapters
|
||||
* @var Zend_Cache_Core
|
||||
*/
|
||||
protected static $_cache = null;
|
||||
|
||||
/**
|
||||
* Scans for the locale within the name of the directory
|
||||
* @constant integer
|
||||
*/
|
||||
const LOCALE_DIRECTORY = 'directory';
|
||||
|
||||
/**
|
||||
* Scans for the locale within the name of the file
|
||||
* @constant integer
|
||||
*/
|
||||
const LOCALE_FILENAME = 'filename';
|
||||
|
||||
/**
|
||||
* Array with all options, each adapter can have own additional options
|
||||
* 'clear' => clears already loaded data when adding new files
|
||||
* 'scan' => searches for translation files using the LOCALE constants
|
||||
* 'locale' => the actual set locale to use
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = array(
|
||||
'clear' => false,
|
||||
'scan' => null,
|
||||
'locale' => 'auto',
|
||||
'ignore' => '.',
|
||||
'disableNotices' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Translation table
|
||||
* @var array
|
||||
*/
|
||||
protected $_translate = array();
|
||||
|
||||
/**
|
||||
* Generates the adapter
|
||||
*
|
||||
* @param string|array $data Translation data or filename for this adapter
|
||||
* @param string|Zend_Locale $locale (optional) Locale/Language to set, identical with Locale
|
||||
* identifiers see Zend_Locale for more information
|
||||
* @param array $options (optional) Options for the adaptor
|
||||
* @throws Zend_Translate_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($data, $locale = null, array $options = array())
|
||||
{
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
if ($result = self::$_cache->load($id)) {
|
||||
$this->_options = unserialize($result);
|
||||
}
|
||||
}
|
||||
|
||||
if (($locale === "auto") or ($locale === null)) {
|
||||
$this->_automatic = true;
|
||||
} else {
|
||||
$this->_automatic = false;
|
||||
}
|
||||
|
||||
$this->addTranslation($data, $locale, $options);
|
||||
$this->setLocale($locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add translation data
|
||||
*
|
||||
* It may be a new language or additional data for existing language
|
||||
* If $clear parameter is true, then translation data for specified
|
||||
* language is replaced and added otherwise
|
||||
*
|
||||
* @param array|string $data Translation data
|
||||
* @param string|Zend_Locale $locale (optional) Locale/Language to add data for, identical
|
||||
* with locale identifier, see Zend_Locale for more information
|
||||
* @param array $options (optional) Option for this Adapter
|
||||
* @throws Zend_Translate_Exception
|
||||
* @return Zend_Translate_Adapter Provides fluent interface
|
||||
*/
|
||||
public function addTranslation($data, $locale = null, array $options = array())
|
||||
{
|
||||
$locale = $this->_getRegistryLocale($locale);
|
||||
$originate = (string) $locale;
|
||||
|
||||
$this->setOptions($options);
|
||||
if (is_string($data) and is_dir($data)) {
|
||||
$prev = '';
|
||||
foreach (new RecursiveIteratorIterator(
|
||||
new RecursiveDirectoryIterator($data, RecursiveDirectoryIterator::KEY_AS_PATHNAME),
|
||||
RecursiveIteratorIterator::SELF_FIRST) as $directory => $info) {
|
||||
$file = $info->getFilename();
|
||||
if (strpos($directory, DIRECTORY_SEPARATOR . $this->_options['ignore']) !== false) {
|
||||
// ignore files matching first characters from option 'ignore' and all files below
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($info->isDir()) {
|
||||
// pathname as locale
|
||||
if (($this->_options['scan'] === self::LOCALE_DIRECTORY) and (Zend_Locale::isLocale($file, true, false))) {
|
||||
if (strlen($prev) <= strlen($file)) {
|
||||
$locale = $file;
|
||||
$prev = (string) $locale;
|
||||
}
|
||||
}
|
||||
} else if ($info->isFile()) {
|
||||
// filename as locale
|
||||
if ($this->_options['scan'] === self::LOCALE_FILENAME) {
|
||||
$filename = explode('.', $file);
|
||||
array_pop($filename);
|
||||
$filename = implode('.', $filename);
|
||||
if (Zend_Locale::isLocale((string) $filename, true, false)) {
|
||||
$locale = (string) $filename;
|
||||
} else {
|
||||
$parts = explode('.', $filename);
|
||||
$parts2 = array();
|
||||
foreach($parts as $token) {
|
||||
$parts2 += explode('_', $token);
|
||||
}
|
||||
$parts = array_merge($parts, $parts2);
|
||||
$parts2 = array();
|
||||
foreach($parts as $token) {
|
||||
$parts2 += explode('-', $token);
|
||||
}
|
||||
$parts = array_merge($parts, $parts2);
|
||||
$parts = array_unique($parts);
|
||||
$prev = '';
|
||||
foreach($parts as $token) {
|
||||
if (Zend_Locale::isLocale($token, true, false)) {
|
||||
if (strlen($prev) <= strlen($token)) {
|
||||
$locale = $token;
|
||||
$prev = $token;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
$this->_addTranslationData($info->getPathname(), (string) $locale, $this->_options);
|
||||
if ((isset($this->_translate[(string) $locale]) === true) and (count($this->_translate[(string) $locale]) > 0)) {
|
||||
$this->setLocale($locale);
|
||||
}
|
||||
} catch (Zend_Translate_Exception $e) {
|
||||
// ignore failed sources while scanning
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$this->_addTranslationData($data, (string) $locale, $this->_options);
|
||||
if ((isset($this->_translate[(string) $locale]) === true) and (count($this->_translate[(string) $locale]) > 0)) {
|
||||
$this->setLocale($locale);
|
||||
}
|
||||
}
|
||||
|
||||
if ((isset($this->_translate[$originate]) === true) and (count($this->_translate[$originate]) > 0)) {
|
||||
$this->setLocale($originate);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets new adapter options
|
||||
*
|
||||
* @param array $options Adapter options
|
||||
* @throws Zend_Translate_Exception
|
||||
* @return Zend_Translate_Adapter Provides fluent interface
|
||||
*/
|
||||
public function setOptions(array $options = array())
|
||||
{
|
||||
foreach ($options as $key => $option) {
|
||||
if ($key == "locale") {
|
||||
$this->setLocale($option);
|
||||
} else {
|
||||
$this->_options[$key] = $option;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
self::$_cache->save( serialize($this->_options), $id);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapters name and it's options
|
||||
*
|
||||
* @param string|null $optionKey String returns this option
|
||||
* null returns all options
|
||||
* @return integer|string|array|null
|
||||
*/
|
||||
public function getOptions($optionKey = null)
|
||||
{
|
||||
if ($optionKey === null) {
|
||||
return $this->_options;
|
||||
}
|
||||
$optionKey = strtolower($optionKey);
|
||||
if (isset($this->_options[$optionKey]) === true) {
|
||||
return $this->_options[$optionKey];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets locale
|
||||
*
|
||||
* @return Zend_Locale|string|null
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
return $this->_options['locale'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets locale
|
||||
*
|
||||
* @param string|Zend_Locale $locale Locale to set
|
||||
* @throws Zend_Translate_Exception
|
||||
* @return Zend_Translate_Adapter Provides fluent interface
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
$locale = $temp[0];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_options['locale'] = $locale;
|
||||
|
||||
if (isset(self::$_cache)) {
|
||||
$id = 'Zend_Translate_' . $this->toString() . '_Options';
|
||||
self::$_cache->save( serialize($this->_options), $id);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the available languages from this adapter
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getList()
|
||||
{
|
||||
$list = array_keys($this->_translate);
|
||||
$result = null;
|
||||
foreach($list as $value) {
|
||||
if (!empty($this->_translate[$value])) {
|
||||
$result[$value] = $value;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all available message ids from this adapter
|
||||
* If no locale is given, the actual language will be used
|
||||
*
|
||||
* @param string|Zend_Locale $locale (optional) Language to return the message ids from
|
||||
* @return array
|
||||
*/
|
||||
public function getMessageIds($locale = null)
|
||||
{
|
||||
if (empty($locale) or !$this->isAvailable($locale)) {
|
||||
$locale = $this->_options['locale'];
|
||||
}
|
||||
|
||||
return array_keys($this->_translate[(string) $locale]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all available translations from this adapter
|
||||
* If no locale is given, the actual language will be used
|
||||
* If 'all' is given the complete translation dictionary will be returned
|
||||
*
|
||||
* @param string|Zend_Locale $locale (optional) Language to return the messages from
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages($locale = null)
|
||||
{
|
||||
if ($locale === 'all') {
|
||||
return $this->_translate;
|
||||
}
|
||||
|
||||
if ((empty($locale) === true) or ($this->isAvailable($locale) === false)) {
|
||||
$locale = $this->_options['locale'];
|
||||
}
|
||||
|
||||
return $this->_translate[(string) $locale];
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the wished language available ?
|
||||
*
|
||||
* @see Zend_Locale
|
||||
* @param string|Zend_Locale $locale Language to search for, identical with locale identifier,
|
||||
* @see Zend_Locale for more information
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAvailable($locale)
|
||||
{
|
||||
$return = isset($this->_translate[(string) $locale]);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translation data
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param string|Zend_Locale $locale
|
||||
* @param array $options (optional)
|
||||
* @return void
|
||||
*/
|
||||
abstract protected function _loadTranslationData($data, $locale, array $options = array());
|
||||
|
||||
/**
|
||||
* Internal function for adding translation data
|
||||
*
|
||||
* It may be a new language or additional data for existing language
|
||||
* If $clear parameter is true, then translation data for specified
|
||||
* language is replaced and added otherwise
|
||||
*
|
||||
* @see Zend_Locale
|
||||
* @param array|string $data Translation data
|
||||
* @param string|Zend_Locale $locale Locale/Language to add data for, identical with locale identifier,
|
||||
* @see Zend_Locale for more information
|
||||
* @param array $options (optional) Option for this Adapter
|
||||
* @throws Zend_Translate_Exception
|
||||
* @return Zend_Translate_Adapter Provides fluent interface
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
$locale = (string) $locale;
|
||||
if (isset($this->_translate[$locale]) === false) {
|
||||
$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);
|
||||
$read = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($read) {
|
||||
$this->_loadTranslationData($data, $locale, $options);
|
||||
}
|
||||
|
||||
if ($this->_automatic === true) {
|
||||
$find = new Zend_Locale($locale);
|
||||
$browser = $find->getEnvironment() + $find->getBrowser();
|
||||
arsort($browser);
|
||||
foreach($browser as $language => $quality) {
|
||||
if (isset($this->_translate[$language]) === true) {
|
||||
$this->_options['locale'] = $language;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given string
|
||||
* returns the translation
|
||||
*
|
||||
* @see Zend_Locale
|
||||
* @param string $messageId Translation string
|
||||
* @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with
|
||||
* locale identifier, @see Zend_Locale for more information
|
||||
* @return string
|
||||
*/
|
||||
public function translate($messageId, $locale = null)
|
||||
{
|
||||
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
|
||||
return $messageId;
|
||||
}
|
||||
$locale = new Zend_Locale($locale);
|
||||
}
|
||||
|
||||
$locale = (string) $locale;
|
||||
if (isset($this->_translate[$locale][$messageId]) === true) {
|
||||
// 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) {
|
||||
// return regionless translation (en_US -> en)
|
||||
return $this->_translate[$locale][$messageId];
|
||||
}
|
||||
}
|
||||
|
||||
// no translation found, return original
|
||||
return $messageId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given string
|
||||
* returns the translation
|
||||
*
|
||||
* @param string $messageId Translation string
|
||||
* @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale
|
||||
* identifier, @see Zend_Locale for more information
|
||||
* @return string
|
||||
*/
|
||||
public function _($messageId, $locale = null)
|
||||
{
|
||||
return $this->translate($messageId, $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a string is translated within the source or not
|
||||
* returns boolean
|
||||
*
|
||||
* @param string $messageId Translation string
|
||||
* @param boolean $original (optional) Allow translation only for original language
|
||||
* when true, a translation for 'en_US' would give false when it can
|
||||
* be translated with 'en' only
|
||||
* @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @return boolean
|
||||
*/
|
||||
public function isTranslated($messageId, $original = false, $locale = null)
|
||||
{
|
||||
if (($original !== false) and ($original !== true)) {
|
||||
$locale = $original;
|
||||
$original = false;
|
||||
}
|
||||
|
||||
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
|
||||
return false;
|
||||
}
|
||||
|
||||
$locale = new Zend_Locale();
|
||||
}
|
||||
|
||||
$locale = (string) $locale;
|
||||
if (isset($this->_translate[$locale][$messageId]) === true) {
|
||||
// return original translation
|
||||
return true;
|
||||
} else if ((strlen($locale) != 2) and ($original === false)) {
|
||||
// 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) {
|
||||
// return regionless translation (en_US -> en)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// No translation found, return original
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the set cache
|
||||
*
|
||||
* @return Zend_Cache_Core The set cache
|
||||
*/
|
||||
public static function getCache()
|
||||
{
|
||||
return self::$_cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a cache for all Zend_Translate_Adapters
|
||||
*
|
||||
* @param Zend_Cache_Core $cache Cache to store to
|
||||
*/
|
||||
public static function setCache(Zend_Cache_Core $cache)
|
||||
{
|
||||
self::$_cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when a cache is set
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static function hasCache()
|
||||
{
|
||||
if (self::$_cache !== null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any set cache
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function removeCache()
|
||||
{
|
||||
self::$_cache = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all set cache data
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function clearCache()
|
||||
{
|
||||
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
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function toString();
|
||||
}
|
89
libs/Zend/Translate/Adapter/Array.php
Normal file
89
libs/Zend/Translate/Adapter/Array.php
Normal file
@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Locale */
|
||||
require_once 'Zend/Locale.php';
|
||||
|
||||
/** Zend_Translate_Adapter */
|
||||
require_once 'Zend/Translate/Adapter.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @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 {
|
||||
/**
|
||||
* Generates the adapter
|
||||
*
|
||||
* @param array $data Translation data
|
||||
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $options OPTIONAL Options to set
|
||||
*/
|
||||
public function __construct($data, $locale = null, array $options = array())
|
||||
{
|
||||
parent::__construct($data, $locale, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translation data
|
||||
*
|
||||
* @param string|array $data
|
||||
* @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
|
||||
*/
|
||||
protected function _loadTranslationData($data, $locale, array $options = array())
|
||||
{
|
||||
if (!is_array($data)) {
|
||||
if (file_exists($data)) {
|
||||
ob_start();
|
||||
$data = include($data);
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
if (!is_array($data)) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
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();
|
||||
}
|
||||
|
||||
$this->_translate[$locale] = $data + $this->_translate[$locale];
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the adapters name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return "Array";
|
||||
}
|
||||
}
|
98
libs/Zend/Translate/Adapter/Csv.php
Normal file
98
libs/Zend/Translate/Adapter/Csv.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Locale */
|
||||
require_once 'Zend/Locale.php';
|
||||
|
||||
/** Zend_Translate_Adapter */
|
||||
require_once 'Zend/Translate/Adapter.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @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 {
|
||||
|
||||
/**
|
||||
* Generates the adapter
|
||||
*
|
||||
* @param string $data Translation data
|
||||
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $options Options for this adapter
|
||||
*/
|
||||
public function __construct($data, $locale = null, array $options = array())
|
||||
{
|
||||
$this->_options['delimiter'] = ";";
|
||||
$this->_options['length'] = 0;
|
||||
$this->_options['enclosure'] = '"';
|
||||
parent::__construct($data, $locale, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translation data
|
||||
*
|
||||
* @param string|array $filename Filename and full path to the translation source
|
||||
* @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
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $options + $this->_options;
|
||||
|
||||
if ($options['clear'] || !isset($this->_translate[$locale])) {
|
||||
$this->_translate[$locale] = array();
|
||||
}
|
||||
|
||||
$this->_file = @fopen($filename, 'rb');
|
||||
if (!$this->_file) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.');
|
||||
}
|
||||
|
||||
while(($data = fgetcsv($this->_file, $options['length'], $options['delimiter'], $options['enclosure'])) !== false) {
|
||||
if (substr($data[0], 0, 1) === '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($data[1]) !== true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->_translate[$locale][$data[0]] = $data[1];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the adapters name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return "Csv";
|
||||
}
|
||||
}
|
169
libs/Zend/Translate/Adapter/Gettext.php
Normal file
169
libs/Zend/Translate/Adapter/Gettext.php
Normal file
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Locale */
|
||||
require_once 'Zend/Locale.php';
|
||||
|
||||
/** Zend_Translate_Adapter */
|
||||
require_once 'Zend/Translate/Adapter.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @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_Gettext extends Zend_Translate_Adapter {
|
||||
// Internal variables
|
||||
private $_bigEndian = false;
|
||||
private $_file = false;
|
||||
private $_adapterInfo = array();
|
||||
|
||||
/**
|
||||
* Generates the adapter
|
||||
*
|
||||
* @param string $data Translation data
|
||||
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $options OPTIONAL Options to set
|
||||
*/
|
||||
public function __construct($data, $locale = null, array $options = array())
|
||||
{
|
||||
parent::__construct($data, $locale, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read values from the MO file
|
||||
*
|
||||
* @param string $bytes
|
||||
*/
|
||||
private function _readMOData($bytes)
|
||||
{
|
||||
if ($this->_bigEndian === false) {
|
||||
return unpack('V' . $bytes, fread($this->_file, 4 * $bytes));
|
||||
} else {
|
||||
return unpack('N' . $bytes, fread($this->_file, 4 * $bytes));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translation data (MO file reader)
|
||||
*
|
||||
* @param string $filename MO file to add, full path must be given for access
|
||||
* @param string $locale New Locale/Language to set, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $option OPTIONAL Options to use
|
||||
* @throws Zend_Translation_Exception
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$this->_bigEndian = false;
|
||||
$options = $options + $this->_options;
|
||||
|
||||
if ($options['clear'] || !isset($this->_translate[$locale])) {
|
||||
$this->_translate[$locale] = array();
|
||||
}
|
||||
|
||||
$this->_file = @fopen($filename, 'rb');
|
||||
if (!$this->_file) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('Error opening translation file \'' . $filename . '\'.');
|
||||
}
|
||||
if (@filesize($filename) < 10) {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('\'' . $filename . '\' is not a gettext file');
|
||||
}
|
||||
|
||||
// get Endian
|
||||
$input = $this->_readMOData(1);
|
||||
if (strtolower(substr(dechex($input[1]), -8)) == "950412de") {
|
||||
$this->_bigEndian = false;
|
||||
} else if (strtolower(substr(dechex($input[1]), -8)) == "de120495") {
|
||||
$this->_bigEndian = true;
|
||||
} else {
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception('\'' . $filename . '\' is not a gettext file');
|
||||
}
|
||||
// read revision - not supported for now
|
||||
$input = $this->_readMOData(1);
|
||||
|
||||
// number of bytes
|
||||
$input = $this->_readMOData(1);
|
||||
$total = $input[1];
|
||||
|
||||
// number of original strings
|
||||
$input = $this->_readMOData(1);
|
||||
$OOffset = $input[1];
|
||||
|
||||
// number of translation strings
|
||||
$input = $this->_readMOData(1);
|
||||
$TOffset = $input[1];
|
||||
|
||||
// fill the original table
|
||||
fseek($this->_file, $OOffset);
|
||||
$origtemp = $this->_readMOData(2 * $total);
|
||||
fseek($this->_file, $TOffset);
|
||||
$transtemp = $this->_readMOData(2 * $total);
|
||||
|
||||
for($count = 0; $count < $total; ++$count) {
|
||||
if ($origtemp[$count * 2 + 1] != 0) {
|
||||
fseek($this->_file, $origtemp[$count * 2 + 2]);
|
||||
$original = @fread($this->_file, $origtemp[$count * 2 + 1]);
|
||||
} else {
|
||||
$original = '';
|
||||
}
|
||||
|
||||
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->_translate[$locale][''] = trim($this->_translate[$locale]['']);
|
||||
if (empty($this->_translate[$locale][''])) {
|
||||
$this->_adapterInfo[$filename] = 'No adapter information available';
|
||||
} else {
|
||||
$this->_adapterInfo[$filename] = $this->_translate[$locale][''];
|
||||
}
|
||||
|
||||
unset($this->_translate[$locale]['']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapter informations
|
||||
*
|
||||
* @return array Each loaded adapter information as array value
|
||||
*/
|
||||
public function getAdapterInfo()
|
||||
{
|
||||
return $this->_adapterInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapter name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return "Gettext";
|
||||
}
|
||||
}
|
81
libs/Zend/Translate/Adapter/Ini.php
Normal file
81
libs/Zend/Translate/Adapter/Ini.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** Zend_Locale */
|
||||
require_once 'Zend/Locale.php';
|
||||
|
||||
/** Zend_Translate_Adapter */
|
||||
require_once 'Zend/Translate/Adapter.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @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_Ini extends Zend_Translate_Adapter
|
||||
{
|
||||
/**
|
||||
* Generates the adapter
|
||||
*
|
||||
* @param array $data Translation data
|
||||
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $options OPTIONAL Options to set
|
||||
*/
|
||||
public function __construct($data, $locale = null, array $options = array())
|
||||
{
|
||||
parent::__construct($data, $locale, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translation data
|
||||
*
|
||||
* @param string|array $data
|
||||
* @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
|
||||
*/
|
||||
protected function _loadTranslationData($data, $locale, array $options = 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();
|
||||
}
|
||||
$this->_translate[$locale] = array_merge($this->_translate[$locale], $inidata);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the adapters name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return "Ini";
|
||||
}
|
||||
}
|
176
libs/Zend/Translate/Adapter/Qt.php
Normal file
176
libs/Zend/Translate/Adapter/Qt.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Locale */
|
||||
require_once 'Zend/Locale.php';
|
||||
|
||||
/** Zend_Translate_Adapter */
|
||||
require_once 'Zend/Translate/Adapter.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @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_Qt extends Zend_Translate_Adapter {
|
||||
// Internal variables
|
||||
private $_file = false;
|
||||
private $_cleared = array();
|
||||
private $_transunit = null;
|
||||
private $_source = null;
|
||||
private $_target = null;
|
||||
private $_scontent = null;
|
||||
private $_tcontent = null;
|
||||
private $_stag = false;
|
||||
private $_ttag = true;
|
||||
|
||||
/**
|
||||
* Generates the Qt adapter
|
||||
* This adapter reads with php's xml_parser
|
||||
*
|
||||
* @param string $data Translation data
|
||||
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $options OPTIONAL Options to set
|
||||
*/
|
||||
public function __construct($data, $locale = null, array $options = array())
|
||||
{
|
||||
parent::__construct($data, $locale, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load translation data (QT file reader)
|
||||
*
|
||||
* @param string $locale Locale/Language to add data for, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @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
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $options + $this->_options;
|
||||
|
||||
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.');
|
||||
}
|
||||
|
||||
$this->_target = $locale;
|
||||
|
||||
$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);
|
||||
xml_set_element_handler($this->_file, "_startElement", "_endElement");
|
||||
xml_set_character_data_handler($this->_file, "_contentElement");
|
||||
|
||||
if (!xml_parse($this->_file, file_get_contents($filename))) {
|
||||
$ex = sprintf('XML error: %s at line %d',
|
||||
xml_error_string(xml_get_error_code($this->_file)),
|
||||
xml_get_current_line_number($this->_file));
|
||||
xml_parser_free($this->_file);
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception($ex);
|
||||
}
|
||||
}
|
||||
|
||||
private function _startElement($file, $name, $attrib)
|
||||
{
|
||||
switch(strtolower($name)) {
|
||||
case 'message':
|
||||
$this->_source = null;
|
||||
$this->_stag = false;
|
||||
$this->_ttag = false;
|
||||
$this->_scontent = null;
|
||||
$this->_tcontent = null;
|
||||
break;
|
||||
case 'source':
|
||||
$this->_stag = true;
|
||||
break;
|
||||
case 'translation':
|
||||
$this->_ttag = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function _endElement($file, $name)
|
||||
{
|
||||
switch (strtolower($name)) {
|
||||
case 'source':
|
||||
$this->_stag = false;
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
$this->_ttag = false;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function _contentElement($file, $data)
|
||||
{
|
||||
if ($this->_stag === true) {
|
||||
$this->_scontent .= $data;
|
||||
}
|
||||
|
||||
if ($this->_ttag === true) {
|
||||
$this->_tcontent .= $data;
|
||||
}
|
||||
}
|
||||
|
||||
private function _findEncoding($filename)
|
||||
{
|
||||
$file = file_get_contents($filename, null, null, 0, 100);
|
||||
if (strpos($file, "encoding") !== false) {
|
||||
$encoding = substr($file, strpos($file, "encoding") + 9);
|
||||
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
|
||||
return $encoding;
|
||||
}
|
||||
return 'UTF-8';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapter name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return "Qt";
|
||||
}
|
||||
}
|
181
libs/Zend/Translate/Adapter/Tbx.php
Normal file
181
libs/Zend/Translate/Adapter/Tbx.php
Normal file
@ -0,0 +1,181 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Locale */
|
||||
require_once 'Zend/Locale.php';
|
||||
|
||||
/** Zend_Translate_Adapter */
|
||||
require_once 'Zend/Translate/Adapter.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @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_Tbx extends Zend_Translate_Adapter {
|
||||
// Internal variables
|
||||
private $_file = false;
|
||||
private $_cleared = array();
|
||||
private $_langset = null;
|
||||
private $_termentry = null;
|
||||
private $_content = null;
|
||||
private $_term = null;
|
||||
|
||||
/**
|
||||
* Generates the tbx adapter
|
||||
* This adapter reads with php's xml_parser
|
||||
*
|
||||
* @param string $data Translation data
|
||||
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $options OPTIONAL Options to set
|
||||
*/
|
||||
public function __construct($data, $locale = null, array $options = array())
|
||||
{
|
||||
parent::__construct($data, $locale, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load translation data (TBX file reader)
|
||||
*
|
||||
* @param string $filename TBX file to add, full path must be given for access
|
||||
* @param string $locale Locale has no effect for TBX because TBX defines all languages within
|
||||
* the source file
|
||||
* @param array $option OPTIONAL Options to use
|
||||
* @throws Zend_Translation_Exception
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $options + $this->_options;
|
||||
|
||||
if ($options['clear']) {
|
||||
$this->_translate = 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);
|
||||
$this->_file = xml_parser_create($encoding);
|
||||
xml_set_object($this->_file, $this);
|
||||
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
|
||||
xml_set_element_handler($this->_file, "_startElement", "_endElement");
|
||||
xml_set_character_data_handler($this->_file, "_contentElement");
|
||||
|
||||
if (!xml_parse($this->_file, file_get_contents($filename))) {
|
||||
$ex = sprintf('XML error: %s at line %d',
|
||||
xml_error_string(xml_get_error_code($this->_file)),
|
||||
xml_get_current_line_number($this->_file));
|
||||
xml_parser_free($this->_file);
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception($ex);
|
||||
}
|
||||
}
|
||||
|
||||
private function _startElement($file, $name, $attrib)
|
||||
{
|
||||
if ($this->_term !== null) {
|
||||
$this->_content .= "<".$name;
|
||||
foreach($attrib as $key => $value) {
|
||||
$this->_content .= " $key=\"$value\"";
|
||||
}
|
||||
$this->_content .= ">";
|
||||
} else {
|
||||
switch(strtolower($name)) {
|
||||
case 'termentry':
|
||||
$this->_termentry = null;
|
||||
break;
|
||||
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();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'term':
|
||||
$this->_term = true;
|
||||
$this->_content = null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _endElement($file, $name)
|
||||
{
|
||||
if (($this->_term !== null) and ($name != "term")) {
|
||||
$this->_content .= "</".$name.">";
|
||||
} else {
|
||||
switch (strtolower($name)) {
|
||||
case 'langset':
|
||||
$this->_langset = null;
|
||||
break;
|
||||
case 'term':
|
||||
$this->_term = null;
|
||||
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;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _contentElement($file, $data)
|
||||
{
|
||||
if ($this->_term !== null) {
|
||||
$this->_content .= $data;
|
||||
}
|
||||
}
|
||||
|
||||
private function _findEncoding($filename)
|
||||
{
|
||||
$file = file_get_contents($filename, null, null, 0, 100);
|
||||
if (strpos($file, "encoding") !== false) {
|
||||
$encoding = substr($file, strpos($file, "encoding") + 9);
|
||||
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
|
||||
return $encoding;
|
||||
}
|
||||
return 'UTF-8';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapter name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return "Tbx";
|
||||
}
|
||||
}
|
183
libs/Zend/Translate/Adapter/Tmx.php
Normal file
183
libs/Zend/Translate/Adapter/Tmx.php
Normal file
@ -0,0 +1,183 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Locale */
|
||||
require_once 'Zend/Locale.php';
|
||||
|
||||
/** Zend_Translate_Adapter */
|
||||
require_once 'Zend/Translate/Adapter.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @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_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;
|
||||
|
||||
/**
|
||||
* Generates the tmx adapter
|
||||
* This adapter reads with php's xml_parser
|
||||
*
|
||||
* @param string $data Translation data
|
||||
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $options OPTIONAL Options to set
|
||||
*/
|
||||
public function __construct($data, $locale = null, array $options = array())
|
||||
{
|
||||
parent::__construct($data, $locale, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load translation data (TMX file reader)
|
||||
*
|
||||
* @param string $filename TMX file to add, full path must be given for access
|
||||
* @param string $locale Locale has no effect for TMX because TMX defines all languages within
|
||||
* the source file
|
||||
* @param array $option OPTIONAL Options to use
|
||||
* @throws Zend_Translation_Exception
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $this->_options + $options;
|
||||
|
||||
if ($options['clear']) {
|
||||
$this->_translate = 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);
|
||||
$this->_file = xml_parser_create($encoding);
|
||||
xml_set_object($this->_file, $this);
|
||||
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
|
||||
xml_set_element_handler($this->_file, "_startElement", "_endElement");
|
||||
xml_set_character_data_handler($this->_file, "_contentElement");
|
||||
|
||||
if (!xml_parse($this->_file, file_get_contents($filename))) {
|
||||
$ex = sprintf('XML error: %s at line %d',
|
||||
xml_error_string(xml_get_error_code($this->_file)),
|
||||
xml_get_current_line_number($this->_file));
|
||||
xml_parser_free($this->_file);
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception($ex);
|
||||
}
|
||||
}
|
||||
|
||||
private function _startElement($file, $name, $attrib)
|
||||
{
|
||||
if ($this->_seg !== null) {
|
||||
$this->_content .= "<".$name;
|
||||
foreach($attrib as $key => $value) {
|
||||
$this->_content .= " $key=\"$value\"";
|
||||
}
|
||||
$this->_content .= ">";
|
||||
} else {
|
||||
switch(strtolower($name)) {
|
||||
case 'tu':
|
||||
if (isset($attrib['tuid']) === true) {
|
||||
$this->_tu = $attrib['tuid'];
|
||||
}
|
||||
break;
|
||||
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();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'seg':
|
||||
$this->_seg = true;
|
||||
$this->_content = null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _endElement($file, $name)
|
||||
{
|
||||
if (($this->_seg !== null) and ($name !== 'seg')) {
|
||||
$this->_content .= "</".$name.">";
|
||||
} else {
|
||||
switch (strtolower($name)) {
|
||||
case 'tu':
|
||||
$this->_tu = null;
|
||||
break;
|
||||
case 'tuv':
|
||||
$this->_tuv = null;
|
||||
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;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _contentElement($file, $data)
|
||||
{
|
||||
if (($this->_seg !== null) and ($this->_tu !== null) and ($this->_tuv !== null)) {
|
||||
$this->_content .= $data;
|
||||
}
|
||||
}
|
||||
|
||||
private function _findEncoding($filename)
|
||||
{
|
||||
$file = file_get_contents($filename, null, null, 0, 100);
|
||||
if (strpos($file, "encoding") !== false) {
|
||||
$encoding = substr($file, strpos($file, "encoding") + 9);
|
||||
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
|
||||
return $encoding;
|
||||
}
|
||||
return 'UTF-8';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapter name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return "Tmx";
|
||||
}
|
||||
}
|
215
libs/Zend/Translate/Adapter/Xliff.php
Normal file
215
libs/Zend/Translate/Adapter/Xliff.php
Normal file
@ -0,0 +1,215 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Locale */
|
||||
require_once 'Zend/Locale.php';
|
||||
|
||||
/** Zend_Translate_Adapter */
|
||||
require_once 'Zend/Translate/Adapter.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @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_Xliff extends Zend_Translate_Adapter {
|
||||
// Internal variables
|
||||
private $_file = false;
|
||||
private $_cleared = array();
|
||||
private $_transunit = null;
|
||||
private $_source = null;
|
||||
private $_target = null;
|
||||
private $_scontent = null;
|
||||
private $_tcontent = null;
|
||||
private $_stag = false;
|
||||
private $_ttag = false;
|
||||
|
||||
/**
|
||||
* Generates the xliff adapter
|
||||
* This adapter reads with php's xml_parser
|
||||
*
|
||||
* @param string $data Translation data
|
||||
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $options OPTIONAL Options to set
|
||||
*/
|
||||
public function __construct($data, $locale = null, array $options = array())
|
||||
{
|
||||
parent::__construct($data, $locale, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load translation data (XLIFF file reader)
|
||||
*
|
||||
* @param string $locale Locale/Language to add data for, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @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
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $options + $this->_options;
|
||||
|
||||
if ($options['clear']) {
|
||||
$this->_translate = 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);
|
||||
$this->_target = $locale;
|
||||
$this->_file = xml_parser_create($encoding);
|
||||
xml_set_object($this->_file, $this);
|
||||
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
|
||||
xml_set_element_handler($this->_file, "_startElement", "_endElement");
|
||||
xml_set_character_data_handler($this->_file, "_contentElement");
|
||||
|
||||
if (!xml_parse($this->_file, file_get_contents($filename))) {
|
||||
$ex = sprintf('XML error: %s at line %d',
|
||||
xml_error_string(xml_get_error_code($this->_file)),
|
||||
xml_get_current_line_number($this->_file));
|
||||
xml_parser_free($this->_file);
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception($ex);
|
||||
}
|
||||
}
|
||||
|
||||
private function _startElement($file, $name, $attrib)
|
||||
{
|
||||
if ($this->_stag === true) {
|
||||
$this->_scontent .= "<".$name;
|
||||
foreach($attrib as $key => $value) {
|
||||
$this->_scontent .= " $key=\"$value\"";
|
||||
}
|
||||
$this->_scontent .= ">";
|
||||
} else if ($this->_ttag === true) {
|
||||
$this->_tcontent .= "<".$name;
|
||||
foreach($attrib as $key => $value) {
|
||||
$this->_tcontent .= " $key=\"$value\"";
|
||||
}
|
||||
$this->_tcontent .= ">";
|
||||
} else {
|
||||
switch(strtolower($name)) {
|
||||
case 'file':
|
||||
$this->_source = $attrib['source-language'];
|
||||
if (isset($attrib['target-language'])) {
|
||||
$this->_target = $attrib['target-language'];
|
||||
}
|
||||
|
||||
$this->_translate[$this->_source] = array();
|
||||
$this->_translate[$this->_target] = array();
|
||||
break;
|
||||
case 'trans-unit':
|
||||
$this->_transunit = true;
|
||||
break;
|
||||
case 'source':
|
||||
if ($this->_transunit === true) {
|
||||
$this->_scontent = null;
|
||||
$this->_stag = true;
|
||||
$this->_ttag = false;
|
||||
}
|
||||
break;
|
||||
case 'target':
|
||||
if ($this->_transunit === true) {
|
||||
$this->_tcontent = null;
|
||||
$this->_ttag = true;
|
||||
$this->_stag = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _endElement($file, $name)
|
||||
{
|
||||
if (($this->_stag === true) and ($name !== 'source')) {
|
||||
$this->_scontent .= "</".$name.">";
|
||||
} else if (($this->_ttag === true) and ($name !== 'target')) {
|
||||
$this->_tcontent .= "</".$name.">";
|
||||
} else {
|
||||
switch (strtolower($name)) {
|
||||
case 'trans-unit':
|
||||
$this->_transunit = null;
|
||||
$this->_scontent = null;
|
||||
$this->_tcontent = null;
|
||||
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;
|
||||
}
|
||||
$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;
|
||||
}
|
||||
$this->_ttag = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function _contentElement($file, $data)
|
||||
{
|
||||
if (($this->_transunit !== null) and ($this->_source !== null) and ($this->_stag === true)) {
|
||||
$this->_scontent .= $data;
|
||||
}
|
||||
|
||||
if (($this->_transunit !== null) and ($this->_target !== null) and ($this->_ttag === true)) {
|
||||
$this->_tcontent .= $data;
|
||||
}
|
||||
}
|
||||
|
||||
private function _findEncoding($filename)
|
||||
{
|
||||
$file = file_get_contents($filename, null, null, 0, 100);
|
||||
if (strpos($file, "encoding") !== false) {
|
||||
$encoding = substr($file, strpos($file, "encoding") + 9);
|
||||
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
|
||||
return $encoding;
|
||||
}
|
||||
return 'UTF-8';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapter name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return "Xliff";
|
||||
}
|
||||
}
|
155
libs/Zend/Translate/Adapter/XmlTm.php
Normal file
155
libs/Zend/Translate/Adapter/XmlTm.php
Normal file
@ -0,0 +1,155 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Date.php 2498 2006-12-23 22:13:38Z thomas $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Locale */
|
||||
require_once 'Zend/Locale.php';
|
||||
|
||||
/** Zend_Translate_Adapter */
|
||||
require_once 'Zend/Translate/Adapter.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @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_XmlTm extends Zend_Translate_Adapter {
|
||||
// Internal variables
|
||||
private $_file = false;
|
||||
private $_cleared = array();
|
||||
private $_lang = null;
|
||||
private $_content = null;
|
||||
private $_tag = null;
|
||||
|
||||
/**
|
||||
* Generates the xmltm adapter
|
||||
* This adapter reads with php's xml_parser
|
||||
*
|
||||
* @param string $data Translation data
|
||||
* @param string|Zend_Locale $locale OPTIONAL Locale/Language to set, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @param array $options OPTIONAL Options to set
|
||||
*/
|
||||
public function __construct($data, $locale = null, array $options = array())
|
||||
{
|
||||
parent::__construct($data, $locale, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load translation data (XMLTM file reader)
|
||||
*
|
||||
* @param string $locale Locale/Language to add data for, identical with locale identifier,
|
||||
* see Zend_Locale for more information
|
||||
* @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
|
||||
*/
|
||||
protected function _loadTranslationData($filename, $locale, array $options = array())
|
||||
{
|
||||
$options = $options + $this->_options;
|
||||
$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);
|
||||
$this->_file = xml_parser_create($encoding);
|
||||
xml_set_object($this->_file, $this);
|
||||
xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
|
||||
xml_set_element_handler($this->_file, "_startElement", "_endElement");
|
||||
xml_set_character_data_handler($this->_file, "_contentElement");
|
||||
|
||||
if (!xml_parse($this->_file, file_get_contents($filename))) {
|
||||
$ex = sprintf('XML error: %s at line %d',
|
||||
xml_error_string(xml_get_error_code($this->_file)),
|
||||
xml_get_current_line_number($this->_file));
|
||||
xml_parser_free($this->_file);
|
||||
require_once 'Zend/Translate/Exception.php';
|
||||
throw new Zend_Translate_Exception($ex);
|
||||
}
|
||||
}
|
||||
|
||||
private function _startElement($file, $name, $attrib)
|
||||
{
|
||||
switch(strtolower($name)) {
|
||||
case 'tm:tu':
|
||||
$this->_tag = $attrib['id'];
|
||||
$this->_content = null;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function _endElement($file, $name)
|
||||
{
|
||||
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;
|
||||
}
|
||||
$this->_tag = null;
|
||||
$this->_content = null;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function _contentElement($file, $data)
|
||||
{
|
||||
if (($this->_tag !== null)) {
|
||||
$this->_content .= $data;
|
||||
}
|
||||
}
|
||||
|
||||
private function _findEncoding($filename)
|
||||
{
|
||||
$file = file_get_contents($filename, null, null, 0, 100);
|
||||
if (strpos($file, "encoding") !== false) {
|
||||
$encoding = substr($file, strpos($file, "encoding") + 9);
|
||||
$encoding = substr($encoding, 1, strpos($encoding, $encoding[0], 1) - 1);
|
||||
return $encoding;
|
||||
}
|
||||
return 'UTF-8';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the adapter name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function toString()
|
||||
{
|
||||
return "XmlTm";
|
||||
}
|
||||
}
|
37
libs/Zend/Translate/Exception.php
Normal file
37
libs/Zend/Translate/Exception.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id: Exception.php 1653 2006-11-16 19:53:38Z thomas $
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Translate
|
||||
* @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_Exception extends Zend_Exception
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user