X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FI18n.php;h=a36389ec7f14a9d9039895b29dc433b0877f105c;hb=4cc3a97e0eb464ef3182f28f1d7fe94606b5b056;hp=55df9d3169d08bec8ec03b228c3302e5df676bbf;hpb=d25dd0ee5e47188c3ea9ad2918f627cfac97ddbd;p=civicrm-core.git diff --git a/CRM/Core/I18n.php b/CRM/Core/I18n.php index 55df9d3169..a36389ec7f 100644 --- a/CRM/Core/I18n.php +++ b/CRM/Core/I18n.php @@ -3,7 +3,7 @@ +--------------------------------------------------------------------+ | CiviCRM version 4.6 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2014 | + | Copyright CiviCRM LLC (c) 2004-2015 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -28,7 +28,7 @@ /** * * @package CRM - * @copyright CiviCRM LLC (c) 2004-2014 + * @copyright CiviCRM LLC (c) 2004-2015 * $Id$ * */ @@ -217,8 +217,9 @@ class CRM_Core_I18n { * @param string $text * the original string. * @param array $params - * the params of the translation (if any). - * + * The params of the translation (if any). + * - domain: string|array a list of translation domains to search (in order) + * - context: string * @return string * the translated string */ @@ -242,6 +243,7 @@ class CRM_Core_I18n { return $text; } + $plural = $count = NULL; if (isset($params['plural'])) { $plural = $params['plural']; unset($params['plural']); @@ -258,10 +260,69 @@ class CRM_Core_I18n { $context = NULL; } + if (isset($params['domain'])) { + $domain = $params['domain']; + unset($params['domain']); + } + else { + $domain = NULL; + } + + $raw = !empty($params['raw']); + unset($params['raw']); + + if (!empty($domain)) { + // It might be prettier to cast to an array, but this is high-traffic stuff. + if (is_array($domain)) { + foreach ($domain as $d) { + $candidate = $this->crm_translate_raw($text, $d, $count, $plural, $context); + if ($candidate != $text) { + $text = $candidate; + break; + } + } + } + else { + $text = $this->crm_translate_raw($text, $domain, $count, $plural, $context); + } + } + else { + $text = $this->crm_translate_raw($text, NULL, $count, $plural, $context); + } + + // replace the numbered %1, %2, etc. params if present + if (count($params) && !$raw) { + $text = $this->strarg($text, $params); + } + + // escape SQL if we were asked for it + if (isset($escape) and ($escape == 'sql')) { + $text = CRM_Core_DAO::escapeString($text); + } + + // escape for JavaScript (if requested) + if (isset($escape) and ($escape == 'js')) { + $text = addcslashes($text, "'"); + } + + return $text; + } + + /** + * Lookup the raw translation of a string (without any extra escaping or interpolation). + * + * @param string $text + * @param string|NULL $domain + * @param int|NULL $count + * @param string $plural + * @param string $context + * @return mixed|string|translated + */ + protected function crm_translate_raw($text, $domain, $count, $plural, $context) { // gettext domain for extensions $domain_changed = FALSE; - if (!empty($params['domain']) && $this->_phpgettext) { - if ($this->setGettextDomain($params['domain'])) { + if (!empty($domain) && $this->_phpgettext) { + if ($this->setGettextDomain($domain)) { $domain_changed = TRUE; } } @@ -324,21 +385,6 @@ class CRM_Core_I18n { } } - // replace the numbered %1, %2, etc. params if present - if (count($params)) { - $text = $this->strarg($text, $params); - } - - // escape SQL if we were asked for it - if (isset($escape) and ($escape == 'sql')) { - $text = CRM_Core_DAO::escapeString($text); - } - - // escape for JavaScript (if requested) - if (isset($escape) and ($escape == 'js')) { - $text = addcslashes($text, "'"); - } - if ($domain_changed) { $this->setGettextDomain('civicrm'); } @@ -467,6 +513,8 @@ class CRM_Core_I18n { /** * Static instance provider - return the instance for the current locale. + * + * @return CRM_Core_I18n */ public static function &singleton() { static $singleton = array();