26 #require_once 'Zend/Locale.php'; 31 #require_once 'Zend/Translate/Plural.php'; 47 private $_automatic =
true;
53 private $_routed = array();
66 private static $_cacheTags =
false;
100 'disableNotices' =>
false,
104 'logMessage' =>
"Untranslated message within '%locale%': %message%",
106 'logUntranslated' =>
false,
110 'tag' =>
'Zend_Translate' 132 }
else if (func_num_args() > 1) {
133 $args = func_get_args();
135 $options[
'content'] = array_shift($args);
138 $options[
'locale'] = array_shift($args);
142 $opt = array_shift($args);
149 if (array_key_exists(
'cache',
$options)) {
154 if (isset(self::$_cache)) {
155 $id =
'Zend_Translate_' . $this->
toString() .
'_Options';
163 $this->_automatic =
true;
165 $this->_automatic =
false;
201 }
else if (func_num_args() > 1) {
202 $args = func_get_args();
204 $options[
'content'] = array_shift($args);
207 $options[
'locale'] = array_shift($args);
211 $opt = array_shift($args);
219 #require_once 'Zend/Translate/Exception.php'; 225 $originate = (string)
$options[
'locale'];
229 #require_once 'Zend/Translate/Exception.php'; 242 #require_once 'Zend/Translate/Exception.php'; 250 $iterator =
new RecursiveIteratorIterator(
251 new RecursiveRegexIterator(
252 new RecursiveDirectoryIterator(
$options[
'content'], RecursiveDirectoryIterator::KEY_AS_PATHNAME),
253 '/^(?!.*(\.svn|\.cvs)).*$/', RecursiveRegexIterator::MATCH
255 RecursiveIteratorIterator::SELF_FIRST
259 $file =
$info->getFilename();
261 foreach (
$options[
'ignore'] as $key => $ignore) {
262 if (strpos($key,
'regex') !==
false) {
263 if (preg_match($ignore, $directory)) {
267 }
else if (strpos($directory, DIRECTORY_SEPARATOR . $ignore) !==
false) {
273 if (strpos($directory, DIRECTORY_SEPARATOR .
$options[
'ignore']) !==
false) {
279 if (
$info->isDir()) {
283 $prev = (string)
$options[
'locale'];
285 }
else if (
$info->isFile()) {
287 if (
$options[
'scan'] === self::LOCALE_FILENAME) {
288 $filename = explode(
'.', $file);
289 array_pop($filename);
290 $filename = implode(
'.', $filename);
292 $options[
'locale'] = (string) $filename;
294 $parts = explode(
'.', $file);
296 foreach($parts as
$token) {
297 $parts2 += explode(
'_',
$token);
299 $parts = array_merge($parts, $parts2);
301 foreach($parts as
$token) {
302 $parts2 += explode(
'-',
$token);
304 $parts = array_merge($parts, $parts2);
305 $parts = array_unique($parts);
307 foreach($parts as
$token) {
309 if (strlen($prev) <= strlen(
$token)) {
320 $this->_addTranslationData(
$options);
329 $this->_addTranslationData(
$options);
332 if ((isset($this->_translate[$originate]) ===
true) and (count($this->_translate[$originate]) > 0)) {
351 if ($key ==
'locale') {
353 }
else if ((isset($this->_options[$key]) and ($this->_options[$key] !=
$option)) or
354 !isset($this->_options[$key])) {
356 #require_once 'Zend/Translate/Exception.php'; 360 if ($key ==
'cache') {
365 $this->_options[$key] =
$option;
370 if ($locale !==
null) {
374 if (isset(self::$_cache) and (
$change ==
true)) {
375 $id =
'Zend_Translate_' . $this->
toString() .
'_Options';
376 if (self::$_cacheTags) {
377 self::$_cache->save($this->_options,
$id, array($this->_options[
'tag']));
379 self::$_cache->save($this->_options,
$id);
395 if ($optionKey ===
null) {
399 if (isset($this->_options[$optionKey]) ===
true) {
400 return $this->_options[$optionKey];
413 return $this->_options[
'locale'];
425 if (($locale ===
"auto") or ($locale ===
null)) {
426 $this->_automatic =
true;
428 $this->_automatic =
false;
434 #require_once 'Zend/Translate/Exception.php'; 438 if (!isset($this->_translate[$locale])) {
439 $temp = explode(
'_', $locale);
440 if (!isset($this->_translate[$temp[0]]) and !isset($this->_translate[$locale])) {
441 if (!$this->_options[
'disableNotices']) {
442 if ($this->_options[
'log']) {
443 $this->_options[
'log']->log(
"The language '{$locale}' has to be added before it can be used.", $this->_options[
'logPriority']);
445 trigger_error(
"The language '{$locale}' has to be added before it can be used.", E_USER_NOTICE);
453 if (empty($this->_translate[$locale])) {
454 if (!$this->_options[
'disableNotices']) {
455 if ($this->_options[
'log']) {
456 $this->_options[
'log']->log(
"No translation for the language '{$locale}' available.", $this->_options[
'logPriority']);
458 trigger_error(
"No translation for the language '{$locale}' available.", E_USER_NOTICE);
463 if ($this->_options[
'locale'] != $locale) {
464 $this->_options[
'locale'] = $locale;
466 if (isset(self::$_cache)) {
467 $id =
'Zend_Translate_' . $this->
toString() .
'_Options';
468 if (self::$_cacheTags) {
469 self::$_cache->save($this->_options,
$id, array($this->_options[
'tag']));
471 self::$_cache->save($this->_options,
$id);
486 $list = array_keys($this->_translate);
488 foreach($list as
$value) {
489 if (!empty($this->_translate[
$value])) {
506 if (empty($locale) or !$this->
isAvailable($locale)) {
507 $locale = $this->_options[
'locale'];
510 return array_search(
$message, $this->_translate[(
string) $locale]);
522 if (empty($locale) or !$this->
isAvailable($locale)) {
523 $locale = $this->_options[
'locale'];
526 return array_keys($this->_translate[(
string) $locale]);
539 if ($locale ===
'all') {
543 if ((empty($locale) ===
true) or ($this->
isAvailable($locale) ===
false)) {
544 $locale = $this->_options[
'locale'];
547 return $this->_translate[(string) $locale];
560 $return = isset($this->_translate[(
string) $locale]);
586 private function _addTranslationData(
$options = array())
590 }
else if (func_num_args() > 1) {
591 $args = func_get_args();
592 $options[
'content'] = array_shift($args);
595 $options[
'locale'] = array_shift($args);
604 $options[
'usetranslateadapter'] =
true;
613 $this->_addTranslationData(
$options);
623 #require_once 'Zend/Translate/Exception.php'; 628 $this->_translate[
$options[
'locale']] = array();
632 if (isset(self::$_cache)) {
634 $temp = self::$_cache->load(
$id);
645 if (!empty(
$options[
'usetranslateadapter'])) {
656 $keys = array_keys($temp);
657 foreach($keys as $key) {
658 if (!isset($this->_translate[$key])) {
659 $this->_translate[$key] = array();
662 if (array_key_exists($key, $temp) && is_array($temp[$key])) {
663 $this->_translate[$key] = $temp[$key] + $this->_translate[$key];
667 if ($this->_automatic ===
true) {
669 $browser = $find->getEnvironment() + $find->getBrowser();
671 foreach($browser as $language => $quality) {
672 if (isset($this->_translate[$language])) {
673 $this->_options[
'locale'] = $language;
679 if (($read) and (isset(self::$_cache))) {
681 if (self::$_cacheTags) {
682 self::$_cache->save($temp,
$id, array($this->_options[
'tag']));
684 self::$_cache->save($temp,
$id);
703 if ($locale ===
null) {
704 $locale = $this->_options[
'locale'];
708 if (is_array($messageId)) {
709 if (count($messageId) > 2) {
710 $number = array_pop($messageId);
713 $number = array_pop($messageId);
718 $plural = $messageId;
719 $messageId = $messageId[0];
721 $messageId = $messageId[0];
728 $this->
_log($messageId, $locale);
730 if (!empty($this->_options[
'route'])) {
731 if (array_key_exists($locale, $this->_options[
'route']) &&
732 !array_key_exists($locale, $this->_routed)) {
733 $this->_routed[$locale] =
true;
734 return $this->
translate($messageId, $this->_options[
'route'][$locale]);
738 $this->_routed = array();
739 if ($plural ===
null) {
744 if (!isset($plural[
$rule])) {
748 return $plural[
$rule];
754 $locale = (string) $locale;
755 if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
757 if ($plural ===
null) {
758 $this->_routed = array();
759 return $this->_translate[$locale][$messageId];
763 if (isset($this->_translate[$locale][$plural[0]][
$rule])) {
764 $this->_routed = array();
765 return $this->_translate[$locale][$plural[0]][
$rule];
767 }
else if (strlen($locale) != 2) {
769 $locale = substr($locale, 0, -strlen(strrchr($locale,
'_')));
771 if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
773 if ($plural ===
null) {
774 $this->_routed = array();
775 return $this->_translate[$locale][$messageId];
779 if (isset($this->_translate[$locale][$plural[0]][
$rule])) {
780 $this->_routed = array();
781 return $this->_translate[$locale][$plural[0]][
$rule];
786 $this->
_log($messageId, $locale);
788 if (!empty($this->_options[
'route'])) {
789 if (array_key_exists($locale, $this->_options[
'route']) &&
790 !array_key_exists($locale, $this->_routed)) {
791 $this->_routed[$locale] =
true;
792 return $this->
translate($messageId, $this->_options[
'route'][$locale]);
796 $this->_routed = array();
797 if ($plural ===
null) {
802 if (!isset($plural[
$rule])) {
806 return $plural[
$rule];
833 if ($this->_options[
'logUntranslated']) {
834 $message = str_replace(
'%message%',
$message, $this->_options[
'logMessage']);
836 if ($this->_options[
'log']) {
837 $this->_options[
'log']->log(
$message, $this->_options[
'logPriority']);
839 trigger_error(
$message, E_USER_NOTICE);
853 public function _($messageId, $locale =
null)
855 return $this->
translate($messageId, $locale);
870 public function isTranslated($messageId, $original =
false, $locale =
null)
872 if (($original !==
false) and ($original !==
true)) {
877 if ($locale ===
null) {
878 $locale = $this->_options[
'locale'];
890 $locale = (string) $locale;
891 if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
894 }
else if ((strlen($locale) != 2) and ($original ===
false)) {
896 $locale = substr($locale, 0, -strlen(strrchr($locale,
'_')));
898 if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
926 self::_getTagSupportForCache();
936 if (self::$_cache !==
null) {
950 self::$_cache =
null;
961 #require_once 'Zend/Cache.php'; 962 if (self::$_cacheTags) {
964 $tag =
'Zend_Translate';
978 abstract public function toString();
985 private static function _getTagSupportForCache()
987 $backend = self::$_cache->getBackend();
989 $cacheOptions = $backend->getCapabilities();
990 self::$_cacheTags = $cacheOptions[
'tags'];
992 self::$_cacheTags =
false;
995 return self::$_cacheTags;
getMessageIds($locale=null)
getMessageId($message, $locale=null)
getOptions($optionKey=null)
__construct($options=array())
_loadTranslationData($data, $locale, array $options=array())
translate($messageId, $locale=null)
static isLocale($locale, $strict=false, $compatible=true)
plural($singular, $plural, $number, $locale=null)
static findLocale($locale=null)
static clearCache($tag=null)
addTranslation($options=array())
setOptions(array $options=array())
static setCache(Zend_Cache_Core $cache)
isTranslated($messageId, $original=false, $locale=null)
_($messageId, $locale=null)
static getPlural($number, $locale)
getMessages($locale=null)
const CLEANING_MODE_MATCHING_TAG
foreach( $_productCollection as $_product)() ?>" class $info