Skip to content

Commit

Permalink
BUGFIX Disable performance intensive Zend_Locale::isLocale() valiatio…
Browse files Browse the repository at this point in the history
…ns in Zend_Translate_Adapter, which is only used for i18n class in SilverStripe core, so a controlled environment where valid locales are assumed
  • Loading branch information
chillu committed Apr 15, 2012
1 parent 95cdbe9 commit 9e95ba0
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions thirdparty/Zend/Translate/Adapter.php
Expand Up @@ -720,34 +720,37 @@ public function translate($messageId, $locale = null)
}
}

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);
// use rerouting when enabled
if (!empty($this->_options['route'])) {
if (array_key_exists($locale, $this->_options['route']) &&
!array_key_exists($locale, $this->_routed)) {
$this->_routed[$locale] = true;
return $this->translate($messageId, $this->_options['route'][$locale]);
}
}

$this->_routed = array();
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);
}
// CUSTOM ischommer: Skip locale checks, too computationally expensive.
// Assume correct locale value is passed in.
// 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);
// // use rerouting when enabled
// if (!empty($this->_options['route'])) {
// if (array_key_exists($locale, $this->_options['route']) &&
// !array_key_exists($locale, $this->_routed)) {
// $this->_routed[$locale] = true;
// return $this->translate($messageId, $this->_options['route'][$locale]);
// }
// }

// $this->_routed = array();
// 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);
// }
// CUSTOM END

$locale = (string) $locale;
if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
Expand Down

0 comments on commit 9e95ba0

Please sign in to comment.