CC-2166: Packaging Improvements. Moved the Zend app into airtime_mvc. It is now installed to /var/www/airtime. Storage is now set to /srv/airtime/stor. Utils are now installed to /usr/lib/airtime/utils/. Added install/airtime-dircheck.php as a simple test to see if everything is install/uninstalled correctly.

This commit is contained in:
Paul Baranowski 2011-04-14 18:55:04 -04:00
parent 514777e8d2
commit b11cbd8159
4546 changed files with 138 additions and 51 deletions

View file

@ -0,0 +1,868 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Adapter.php 21662 2010-03-27 20:23:42Z thomas $
*/
/**
* @see Zend_Locale
*/
require_once 'Zend/Locale.php';
/**
* @see Zend_Translate_Plural
*/
require_once 'Zend/Translate/Plural.php';
/**
* Basic adapter class for each translation source adapter
*
* @category Zend
* @package Zend_Translate
* @subpackage Zend_Translate_Adapter
* @copyright Copyright (c) 2005-2010 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' => when true, clears already loaded translations when adding new files
* 'content' => content to translate or file or directory with content
* 'disableNotices' => when true, omits notices from being displayed
* 'ignore' => a prefix for files and directories which are not being added
* 'locale' => the actual set locale to use
* 'log' => a instance of Zend_Log where logs are written to
* 'logMessage' => message to be logged
* 'logUntranslated' => when true, untranslated messages are not logged
* 'reload' => reloads the cache by reading the content again
* 'scan' => searches for translation files using the LOCALE constants
*
* @var array
*/
protected $_options = array(
'clear' => false,
'content' => null,
'disableNotices' => false,
'ignore' => '.',
'locale' => 'auto',
'log' => null,
'logMessage' => "Untranslated message within '%locale%': %message%",
'logUntranslated' => false,
'reload' => false,
'scan' => null
);
/**
* Translation table
* @var array
*/
protected $_translate = array();
/**
* Generates the adapter
*
* @param array|Zend_Config $options Translation options for this adapter
* @throws Zend_Translate_Exception
* @return void
*/
public function __construct($options = array())
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (func_num_args() > 1) {
$args = func_get_args();
$options = array();
$options['content'] = array_shift($args);
if (!empty($args)) {
$options['locale'] = array_shift($args);
}
if (!empty($args)) {
$opt = array_shift($args);
$options = array_merge($opt, $options);
}
} else if (!is_array($options)) {
$options = array('content' => $options);
}
if (isset(self::$_cache)) {
$id = 'Zend_Translate_' . $this->toString() . '_Options';
$result = self::$_cache->load($id);
if ($result) {
$this->_options = $result;
}
}
if (empty($options['locale']) || ($options['locale'] === "auto")) {
$this->_automatic = true;
} else {
$this->_automatic = false;
}
$locale = null;
if (!empty($options['locale'])) {
$locale = $options['locale'];
unset($options['locale']);
}
$this->setOptions($options);
$options['locale'] = $locale;
if (!empty($options['content'])) {
$this->addTranslation($options);
}
if ($this->getLocale() !== (string) $options['locale']) {
$this->setLocale($options['locale']);
}
}
/**
* Add translations
*
* This may be a new language or additional content for an existing language
* If the key 'clear' is true, then translations for the specified
* language will be replaced and added otherwise
*
* @param array|Zend_Config $options Options and translations to be added
* @throws Zend_Translate_Exception
* @return Zend_Translate_Adapter Provides fluent interface
*/
public function addTranslation($options = array())
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (func_num_args() > 1) {
$args = func_get_args();
$options = array();
$options['content'] = array_shift($args);
if (!empty($args)) {
$options['locale'] = array_shift($args);
}
if (!empty($args)) {
$opt = array_shift($args);
$options = array_merge($opt, $options);
}
} else if (!is_array($options)) {
$options = array('content' => $options);
}
$originate = null;
if (!empty($options['locale'])) {
$originate = (string) $options['locale'];
}
if ((array_key_exists('log', $options)) && !($options['log'] instanceof Zend_Log)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('Instance of Zend_Log expected for option log');
}
try {
if (!($options['content'] instanceof Zend_Translate) && !($options['content'] instanceof Zend_Translate_Adapter)) {
$options['locale'] = Zend_Locale::findLocale($options['locale']);
}
} catch (Zend_Locale_Exception $e) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception("The given Language '{$options['locale']}' does not exist", 0, $e);
}
$options = $options + $this->_options;
if (is_string($options['content']) and is_dir($options['content'])) {
$options['content'] = realpath($options['content']);
$prev = '';
foreach (new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($options['content'], RecursiveDirectoryIterator::KEY_AS_PATHNAME),
RecursiveIteratorIterator::SELF_FIRST) as $directory => $info) {
$file = $info->getFilename();
if (is_array($options['ignore'])) {
foreach ($options['ignore'] as $key => $ignore) {
if (strpos($key, 'regex') !== false) {
if (preg_match($ignore, $directory)) {
// ignore files matching the given regex from option 'ignore' and all files below
continue 2;
}
} else if (strpos($directory, DIRECTORY_SEPARATOR . $ignore) !== false) {
// ignore files matching first characters from option 'ignore' and all files below
continue 2;
}
}
} else {
if (strpos($directory, DIRECTORY_SEPARATOR . $options['ignore']) !== false) {
// ignore files matching first characters from option 'ignore' and all files below
continue;
}
}
if ($info->isDir()) {
// pathname as locale
if (($options['scan'] === self::LOCALE_DIRECTORY) and (Zend_Locale::isLocale($file, true, false))) {
$options['locale'] = $file;
$prev = (string) $options['locale'];
}
} else if ($info->isFile()) {
// filename as locale
if ($options['scan'] === self::LOCALE_FILENAME) {
$filename = explode('.', $file);
array_pop($filename);
$filename = implode('.', $filename);
if (Zend_Locale::isLocale((string) $filename, true, false)) {
$options['locale'] = (string) $filename;
} else {
$parts = explode('.', $file);
$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)) {
$options['locale'] = $token;
$prev = $token;
}
}
}
}
}
try {
$options['content'] = $info->getPathname();
$this->_addTranslationData($options);
} catch (Zend_Translate_Exception $e) {
// ignore failed sources while scanning
}
}
}
} else {
$this->_addTranslationData($options);
}
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())
{
$change = false;
$locale = null;
foreach ($options as $key => $option) {
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 ($locale !== null) {
$this->setLocale($locale);
}
if (isset(self::$_cache) and ($change == true)) {
$id = 'Zend_Translate_' . $this->toString() . '_Options';
self::$_cache->save($this->_options, $id, array('Zend_Translate'));
}
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;
}
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)
{
if (($locale === "auto") or ($locale === null)) {
$this->_automatic = true;
} else {
$this->_automatic = false;
}
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", 0, $e);
}
if (!isset($this->_translate[$locale])) {
$temp = explode('_', $locale);
if (!isset($this->_translate[$temp[0]]) and !isset($this->_translate[$locale])) {
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);
}
}
}
$locale = $temp[0];
}
if (empty($this->_translate[$locale])) {
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);
}
}
}
if ($this->_options['locale'] != $locale) {
$this->_options['locale'] = $locale;
if (isset(self::$_cache)) {
$id = 'Zend_Translate_' . $this->toString() . '_Options';
self::$_cache->save($this->_options, $id, array('Zend_Translate'));
}
}
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 array
*/
abstract protected function _loadTranslationData($data, $locale, array $options = array());
/**
* Internal function for adding translation data
*
* This may be a new language or additional data for an existing language
* If the options 'clear' is true, then the translation data for the specified
* language is replaced and added otherwise
*
* @see Zend_Locale
* @param array|Zend_Config $content Translation data to add
* @throws Zend_Translate_Exception
* @return Zend_Translate_Adapter Provides fluent interface
*/
private function _addTranslationData($options = array())
{
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (func_num_args() > 1) {
$args = func_get_args();
$options['content'] = array_shift($args);
if (!empty($args)) {
$options['locale'] = array_shift($args);
}
if (!empty($args)) {
$options += array_shift($args);
}
}
if (($options['content'] instanceof Zend_Translate) || ($options['content'] instanceof Zend_Translate_Adapter)) {
$options['usetranslateadapter'] = true;
if (!empty($options['locale'])) {
$options['content'] = $options['content']->getMessages($options['locale']);
} else {
$locales = $options['content']->getList();
foreach ($locales as $locale) {
$options['locale'] = $locale;
$options['content'] = $options['content']->getMessages($locale);
$this->_addTranslationData($options);
}
return $this;
}
}
try {
$options['locale'] = Zend_Locale::findLocale($options['locale']);
} catch (Zend_Locale_Exception $e) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception("The given Language '{$options['locale']}' does not exist", 0, $e);
}
if ($options['clear'] || !isset($this->_translate[$options['locale']])) {
$this->_translate[$options['locale']] = array();
}
$read = true;
if (isset(self::$_cache)) {
$id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString();
$temp = self::$_cache->load($id);
if ($temp) {
$read = false;
}
}
if ($options['reload']) {
$read = true;
}
if ($read) {
if (!empty($options['usetranslateadapter'])) {
$temp = array($options['locale'] => $options['content']);
} else {
$temp = $this->_loadTranslationData($options['content'], $options['locale'], $options);
}
}
if (empty($temp)) {
$temp = array();
}
$keys = array_keys($temp);
foreach($keys as $key) {
if (!isset($this->_translate[$key])) {
$this->_translate[$key] = array();
}
if (array_key_exists($key, $temp) && is_array($temp[$key])) {
$this->_translate[$key] = $temp[$key] + $this->_translate[$key];
}
}
if ($this->_automatic === true) {
$find = new Zend_Locale($options['locale']);
$browser = $find->getEnvironment() + $find->getBrowser();
arsort($browser);
foreach($browser as $language => $quality) {
if (isset($this->_translate[$language])) {
$this->_options['locale'] = $language;
break;
}
}
}
if (($read) and (isset(self::$_cache))) {
$id = 'Zend_Translate_' . md5(serialize($options['content'])) . '_' . $this->toString();
self::$_cache->save($temp, $id, array('Zend_Translate'));
}
return $this;
}
/**
* Translates the given string
* returns the translation
*
* @see Zend_Locale
* @param string|array $messageId Translation string, or Array for plural translations
* @param string|Zend_Locale $locale (optional) Locale/Language to use, identical with
* locale identifier, @see Zend_Locale for more information
* @return string
*/
public function translate($messageId, $locale = null)
{
if ($locale === null) {
$locale = $this->_options['locale'];
}
$plural = null;
if (is_array($messageId)) {
if (count($messageId) > 2) {
$number = array_pop($messageId);
if (!is_numeric($number)) {
$plocale = $number;
$number = array_pop($messageId);
} else {
$plocale = 'en';
}
$plural = $messageId;
$messageId = $messageId[0];
} else {
$messageId = $messageId[0];
}
}
if (!Zend_Locale::isLocale($locale, true, false)) {
if (!Zend_Locale::isLocale($locale, false, false)) {
// language does not exist, return original string
$this->_log($messageId, $locale);
if ($plural === null) {
return $messageId;
}
$rule = Zend_Translate_Plural::getPlural($number, $plocale);
if (!isset($plural[$rule])) {
$rule = 0;
}
return $plural[$rule];
}
$locale = new Zend_Locale($locale);
}
$locale = (string) $locale;
if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
// return original translation
if ($plural === null) {
return $this->_translate[$locale][$messageId];
}
$rule = Zend_Translate_Plural::getPlural($number, $locale);
if (isset($this->_translate[$locale][$plural[0]][$rule])) {
return $this->_translate[$locale][$plural[0]][$rule];
}
} else if (strlen($locale) != 2) {
// faster than creating a new locale and separate the leading part
$locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
// return regionless translation (en_US -> en)
if ($plural === null) {
return $this->_translate[$locale][$messageId];
}
$rule = Zend_Translate_Plural::getPlural($number, $locale);
if (isset($this->_translate[$locale][$plural[0]][$rule])) {
return $this->_translate[$locale][$plural[0]][$rule];
}
}
}
$this->_log($messageId, $locale);
if ($plural === null) {
return $messageId;
}
$rule = Zend_Translate_Plural::getPlural($number, $plocale);
if (!isset($plural[$rule])) {
$rule = 0;
}
return $plural[$rule];
}
/**
* Translates the given string using plural notations
* Returns the translated string
*
* @see Zend_Locale
* @param string $singular Singular translation string
* @param string $plural Plural translation string
* @param integer $number Number for detecting the correct plural
* @param string|Zend_Locale $locale (Optional) Locale/Language to use, identical with
* locale identifier, @see Zend_Locale for more information
* @return string
*/
public function plural($singular, $plural, $number, $locale = null)
{
return $this->translate(array($singular, $plural, $number), $locale);
}
/**
* 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
*
* @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);
}
$locale = (string) $locale;
if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
// 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 ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
// 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()
{
require_once 'Zend/Cache.php';
self::$_cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('Zend_Translate'));
}
/**
* Returns the adapter name
*
* @return string
*/
abstract public function toString();
}

View 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Array.php 20096 2010-01-06 02:05:09Z bkarwin $
* @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-2010 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
{
private $_data = array();
/**
* 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
* @return array
*/
protected function _loadTranslationData($data, $locale, array $options = array())
{
$this->_data = 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."'");
}
if (!isset($this->_data[$locale])) {
$this->_data[$locale] = array();
}
$this->_data[$locale] = $data + $this->_data[$locale];
return $this->_data;
}
/**
* returns the adapters name
*
* @return string
*/
public function toString()
{
return "Array";
}
}

View file

@ -0,0 +1,121 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Csv.php 21662 2010-03-27 20:23:42Z 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-2010 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
{
private $_data = array();
/**
* Generates the adapter
*
* @param array|Zend_Config $options Translation content
*/
public function __construct($options = array())
{
$this->_options['delimiter'] = ";";
$this->_options['length'] = 0;
$this->_options['enclosure'] = '"';
if ($options instanceof Zend_Config) {
$options = $options->toArray();
} else if (func_num_args() > 1) {
$args = func_get_args();
$options = array();
$options['content'] = array_shift($args);
if (!empty($args)) {
$options['locale'] = array_shift($args);
}
if (!empty($args)) {
$opt = array_shift($args);
$options = array_merge($opt, $options);
}
} else if (!is_array($options)) {
$options = array('content' => $options);
}
parent::__construct($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
* @return array
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$this->_data = array();
$options = $options + $this->_options;
$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])) {
continue;
}
if (count($data) == 2) {
$this->_data[$locale][$data[0]] = $data[1];
} else {
$singular = array_shift($data);
$this->_data[$locale][$singular] = $data;
}
}
return $this->_data;
}
/**
* returns the adapters name
*
* @return string
*/
public function toString()
{
return "Csv";
}
}

View file

@ -0,0 +1,165 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Gettext.php 20096 2010-01-06 02:05:09Z bkarwin $
* @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-2010 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();
private $_data = array();
/**
* 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
* @return array
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$this->_data = array();
$this->_bigEndian = false;
$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]);
$original = explode(chr(00), $original);
} else {
$original[0] = '';
}
if ($transtemp[$count * 2 + 1] != 0) {
fseek($this->_file, $transtemp[$count * 2 + 2]);
$translate = fread($this->_file, $transtemp[$count * 2 + 1]);
$translate = explode(chr(00), $translate);
if ((count($original) > 1) && (count($translate) > 1)) {
$this->_data[$locale][$original[0]] = $translate;
array_shift($original);
foreach ($original as $orig) {
$this->_data[$locale][$orig] = '';
}
} else {
$this->_data[$locale][$original[0]] = $translate[0];
}
}
}
$this->_data[$locale][''] = trim($this->_data[$locale]['']);
if (empty($this->_data[$locale][''])) {
$this->_adapterInfo[$filename] = 'No adapter information available';
} else {
$this->_adapterInfo[$filename] = $this->_data[$locale][''];
}
unset($this->_data[$locale]['']);
return $this->_data;
}
/**
* 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";
}
}

View file

@ -0,0 +1,74 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Ini.php 20096 2010-01-06 02:05:09Z bkarwin $
* @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-2010 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
{
private $_data = array();
/**
* 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
* @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);
if (!isset($this->_data[$locale])) {
$this->_data[$locale] = array();
}
$this->_data[$locale] = array_merge($this->_data[$locale], $inidata);
return $this->_data;
}
/**
* returns the adapters name
*
* @return string
*/
public function toString()
{
return "Ini";
}
}

View file

@ -0,0 +1,160 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Qt.php 20096 2010-01-06 02:05:09Z bkarwin $
* @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-2010 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;
private $_data = array();
/**
* 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
* @return array
*/
protected function _loadTranslationData($filename, $locale, array $options = 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.');
}
$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);
}
return $this->_data;
}
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->_data[$this->_target][$this->_scontent]) === false)) {
$this->_data[$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";
}
}

View file

@ -0,0 +1,165 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Tbx.php 20096 2010-01-06 02:05:09Z bkarwin $
* @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-2010 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;
private $_data = array();
/**
* 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
* @return array
*/
protected function _loadTranslationData($filename, $locale, array $options = 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.');
}
$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);
}
return $this->_data;
}
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->_data[$this->_langset]) === false) {
$this->_data[$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->_data[$this->_langset][$this->_termentry]) === false)) {
$this->_data[$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";
}
}

View file

@ -0,0 +1,233 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Tmx.php 21050 2010-02-13 22:53:40Z 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-2010 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 $_useId = true;
private $_srclang = null;
private $_tu = null;
private $_tuv = null;
private $_seg = null;
private $_content = null;
private $_data = array();
/**
* 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
* @return array
*/
protected function _loadTranslationData($filename, $locale, array $options = 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.');
}
if (isset($options['useId'])) {
$this->_useId = (boolean) $options['useId'];
}
$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);
}
return $this->_data;
}
/**
* Internal method, called by xml element handler at start
*
* @param resource $file File handler
* @param string $name Elements name
* @param array $attrib Attributes for this element
*/
protected 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 'header':
if (empty($this->_useId) && isset($attrib['srclang'])) {
if (Zend_Locale::isLocale($attrib['srclang'])) {
$this->_srclang = Zend_Locale::findLocale($attrib['srclang']);
} else {
if (!$this->_options['disableNotices']) {
if ($this->_options['log']) {
$this->_options['log']->notice("The language '{$attrib['srclang']}' can not be set because it does not exist.");
} else {
trigger_error("The language '{$attrib['srclang']}' can not be set because it does not exist.", E_USER_NOTICE);
}
}
$this->_srclang = $attrib['srclang'];
}
}
break;
case 'tu':
if (isset($attrib['tuid'])) {
$this->_tu = $attrib['tuid'];
}
break;
case 'tuv':
if (isset($attrib['xml:lang'])) {
if (Zend_Locale::isLocale($attrib['xml:lang'])) {
$this->_tuv = Zend_Locale::findLocale($attrib['xml:lang']);
} else {
if (!$this->_options['disableNotices']) {
if ($this->_options['log']) {
$this->_options['log']->notice("The language '{$attrib['xml:lang']}' can not be set because it does not exist.");
} else {
trigger_error("The language '{$attrib['xml:lang']}' can not be set because it does not exist.", E_USER_NOTICE);
}
}
$this->_tuv = $attrib['xml:lang'];
}
if (!isset($this->_data[$this->_tuv])) {
$this->_data[$this->_tuv] = array();
}
}
break;
case 'seg':
$this->_seg = true;
$this->_content = null;
break;
default:
break;
}
}
}
/**
* Internal method, called by xml element handler at end
*
* @param resource $file File handler
* @param string $name Elements name
*/
protected 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->_srclang) && ($this->_srclang == $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:
break;
}
}
}
/**
* Internal method, called by xml element handler for content
*
* @param resource $file File handler
* @param string $data Elements content
*/
protected function _contentElement($file, $data)
{
if (($this->_seg !== null) and ($this->_tu !== null) and ($this->_tuv !== null)) {
$this->_content .= $data;
}
}
/**
* Internal method, detects the encoding of the xml file
*
* @param string $name Filename
* @return string Encoding
*/
protected 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";
}
}

View file

@ -0,0 +1,229 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Xliff.php 20096 2010-01-06 02:05:09Z bkarwin $
* @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-2010 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 $_useId = true;
private $_cleared = array();
private $_transunit = null;
private $_source = null;
private $_target = null;
private $_langId = null;
private $_scontent = null;
private $_tcontent = null;
private $_stag = false;
private $_ttag = false;
private $_data = array();
/**
* 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
* @return array
*/
protected function _loadTranslationData($filename, $locale, array $options = 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.');
}
if (empty($options['useId'])) {
$this->_useId = false;
} else {
$this->_useId = true;
}
$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);
}
return $this->_data;
}
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'];
}
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;
$this->_langId = $attrib['id'];
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->_langId = null;
$this->_scontent = null;
$this->_tcontent = null;
break;
case 'source':
if ($this->_useId) {
if (!empty($this->_scontent) && !empty($this->_langId) &&
!isset($this->_data[$this->_source][$this->_langId])) {
$this->_data[$this->_source][$this->_langId] = $this->_scontent;
}
} else {
if (!empty($this->_scontent) &&
!isset($this->_data[$this->_source][$this->_scontent])) {
$this->_data[$this->_source][$this->_scontent] = $this->_scontent;
}
}
$this->_stag = false;
break;
case 'target':
if ($this->_useId) {
if (!empty($this->_tcontent) && !empty($this->_langId) &&
!isset($this->_data[$this->_target][$this->_langId])) {
$this->_data[$this->_target][$this->_langId] = $this->_tcontent;
}
} else {
if (!empty($this->_tcontent) && !empty($this->_scontent) &&
!isset($this->_data[$this->_target][$this->_scontent])) {
$this->_data[$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";
}
}

View file

@ -0,0 +1,139 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: XmlTm.php 20096 2010-01-06 02:05:09Z bkarwin $
* @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-2010 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;
private $_data = array();
/**
* 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
* @return array
*/
protected function _loadTranslationData($filename, $locale, array $options = array())
{
$this->_data = array();
$this->_lang = $locale;
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);
}
return $this->_data;
}
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->_data[$this->_lang][$this->_tag]) === false)) {
$this->_data[$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";
}
}

View 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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id: Exception.php 20096 2010-01-06 02:05:09Z bkarwin $
* @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-2010 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
{
}

View file

@ -0,0 +1,224 @@
<?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_Locale
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Plural.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* Utility class for returning the plural rules according to the given locale
*
* @category Zend
* @package Zend_Locale
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Translate_Plural
{
/**
* Manual rule to use
*
* @var string
*/
protected static $_plural = array();
/**
* Returns the plural definition to use
*
* @param integer $number Number for plural selection
* @param string $locale Locale to use
* @return integer Plural number to use
*/
public static function getPlural($number, $locale)
{
if ($locale == "pt_BR") {
// temporary set a locale for brasilian
$locale = "xbr";
}
if (strlen($locale) > 3) {
$locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
}
if (isset(self::$_plural[$locale])) {
$return = call_user_func(self::$_plural[$locale], $number);
if (!is_int($return) || ($return < 0)) {
$return = 0;
}
return $return;
}
switch($locale) {
case 'bo':
case 'dz':
case 'id':
case 'ja':
case 'jv':
case 'ka':
case 'km':
case 'kn':
case 'ko':
case 'ms':
case 'th':
case 'tr':
case 'vi':
case 'zh':
return 0;
break;
case 'af':
case 'az':
case 'bn':
case 'bg':
case 'ca':
case 'da':
case 'de':
case 'el':
case 'en':
case 'eo':
case 'es':
case 'et':
case 'eu':
case 'fa':
case 'fi':
case 'fo':
case 'fur':
case 'fy':
case 'gl':
case 'gu':
case 'ha':
case 'he':
case 'hu':
case 'is':
case 'it':
case 'ku':
case 'lb':
case 'ml':
case 'mn':
case 'mr':
case 'nah':
case 'nb':
case 'ne':
case 'nl':
case 'nn':
case 'no':
case 'om':
case 'or':
case 'pa':
case 'pap':
case 'ps':
case 'pt':
case 'so':
case 'sq':
case 'sv':
case 'sw':
case 'ta':
case 'te':
case 'tk':
case 'ur':
case 'zu':
return ($number == 1) ? 0 : 1;
case 'am':
case 'bh':
case 'fil':
case 'fr':
case 'gun':
case 'hi':
case 'ln':
case 'mg':
case 'nso':
case 'xbr':
case 'ti':
case 'wa':
return (($number == 0) || ($number == 1)) ? 0 : 1;
case 'be':
case 'bs':
case 'hr':
case 'ru':
case 'sr':
case 'uk':
return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
case 'cs':
case 'sk':
return ($number == 1) ? 0 : ((($number >= 2) && ($number <= 4)) ? 1 : 2);
case 'ga':
return ($number == 1) ? 0 : (($number == 2) ? 1 : 2);
case 'lt':
return (($number % 10 == 1) && ($number % 100 != 11)) ? 0 : ((($number % 10 >= 2) && (($number % 100 < 10) || ($number % 100 >= 20))) ? 1 : 2);
case 'sl':
return ($number % 100 == 1) ? 0 : (($number % 100 == 2) ? 1 : ((($number % 100 == 3) || ($number % 100 == 4)) ? 2 : 3));
case 'mk':
return ($number % 10 == 1) ? 0 : 1;
case 'mt':
return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 1) && ($number % 100 < 11))) ? 1 : ((($number % 100 > 10) && ($number % 100 < 20)) ? 2 : 3));
case 'lv':
return ($number == 0) ? 0 : ((($number % 10 == 1) && ($number % 100 != 11)) ? 1 : 2);
case 'pl':
return ($number == 1) ? 0 : ((($number % 10 >= 2) && ($number % 10 <= 4) && (($number % 100 < 10) || ($number % 100 > 29))) ? 1 : 2);
case 'cy':
return ($number == 1) ? 0 : (($number == 2) ? 1 : ((($number == 8) || ($number == 11)) ? 2 : 3));
case 'ro':
return ($number == 1) ? 0 : ((($number == 0) || (($number % 100 > 0) && ($number % 100 < 20))) ? 1 : 2);
case 'ar':
return ($number == 0) ? 0 : (($number == 1) ? 1 : (($number == 2) ? 2 : ((($number >= 3) && ($number <= 10)) ? 3 : ((($number >= 11) && ($number <= 99)) ? 4 : 5))));
default:
return 0;
}
}
/**
* Set's a new plural rule
*
* @param string $rule Callback which acts as rule
* @param string $locale Locale which is used for this callback
* @return null
*/
public static function setPlural($rule, $locale)
{
if ($locale == "pt_BR") {
// temporary set a locale for brasilian
$locale = "xbr";
}
if (strlen($locale) > 3) {
$locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
}
if (!is_callable($rule)) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception('The given rule can not be called');
}
self::$_plural[$locale] = $rule;
}
}

View file

@ -0,0 +1,180 @@
<?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-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Translate.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
/**
* @see Zend_Loader
*/
require_once 'Zend/Loader.php';
/**
* @category Zend
* @package Zend_Translate
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_Translate {
/**
* Adapter names constants
*/
const AN_ARRAY = 'Array';
const AN_CSV = 'Csv';
const AN_GETTEXT = 'Gettext';
const AN_INI = 'Ini';
const AN_QT = 'Qt';
const AN_TBX = 'Tbx';
const AN_TMX = 'Tmx';
const AN_XLIFF = 'Xliff';
const AN_XMLTM = 'XmlTm';
const LOCALE_DIRECTORY = 'directory';
const LOCALE_FILENAME = 'filename';
/**
* Adapter
*
* @var Zend_Translate_Adapter
*/
private $_adapter;
private static $_cache = null;
/**
* Generates the standard translation object
*
* @param string $adapter Adapter to use
* @param array $data OPTIONAL Translation source data for the adapter
* Depends on the Adapter
* @param string|Zend_Locale $locale OPTIONAL locale to use
* @param array $options OPTIONAL options for the adapter
* @throws Zend_Translate_Exception
*/
public function __construct($adapter, $data = null, $locale = null, array $options = array())
{
$this->setAdapter($adapter, $data, $locale, $options);
}
/**
* Sets a new adapter
*
* @param string $adapter Adapter to use
* @param string|array $data OPTIONAL Translation data
* @param string|Zend_Locale $locale OPTIONAL locale to use
* @param array $options OPTIONAL Options to use
* @throws Zend_Translate_Exception
*/
public function setAdapter($adapter, $data = null, $locale = null, array $options = array())
{
if (Zend_Loader::isReadable('Zend/Translate/Adapter/' . ucfirst($adapter). '.php')) {
$adapter = 'Zend_Translate_Adapter_' . ucfirst($adapter);
}
if (!class_exists($adapter)) {
Zend_Loader::loadClass($adapter);
}
if (self::$_cache !== null) {
call_user_func(array($adapter, 'setCache'), self::$_cache);
}
$this->_adapter = new $adapter($data, $locale, $options);
if (!$this->_adapter instanceof Zend_Translate_Adapter) {
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception("Adapter " . $adapter . " does not extend Zend_Translate_Adapter");
}
}
/**
* Returns the adapters name and it's options
*
* @return Zend_Translate_Adapter
*/
public function getAdapter()
{
return $this->_adapter;
}
/**
* Returns the set cache
*
* @return Zend_Cache_Core The set cache
*/
public static function getCache()
{
return self::$_cache;
}
/**
* Sets a cache for all instances of Zend_Translate
*
* @param Zend_Cache_Core $cache Cache to store to
* @return void
*/
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();
}
/**
* Calls all methods from the adapter
*/
public function __call($method, array $options)
{
if (method_exists($this->_adapter, $method)) {
return call_user_func_array(array($this->_adapter, $method), $options);
}
require_once 'Zend/Translate/Exception.php';
throw new Zend_Translate_Exception("Unknown method '" . $method . "' called!");
}
}