| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
/**
*
* @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
*/
return $text;
}
+ $plural = $count = NULL;
if (isset($params['plural'])) {
$plural = $params['plural'];
unset($params['plural']);
$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;
}
}
}
}
- // 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');
}
/**
* Static instance provider - return the instance for the current locale.
+ *
+ * @return CRM_Core_I18n
*/
public static function &singleton() {
static $singleton = array();
return $locales[$tsLocale];
}
+
}
/**