+ 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) {