/**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $config = CRM_Core_Config::singleton();
     $values = CRM_Core_BAO_WordReplacement::getLocaleCustomStrings($config->lcMessages);
     //CRM-14179
     $instances = 0;
     foreach ($values as $valMatchType) {
         foreach ($valMatchType as $valPairs) {
             $instances += count($valPairs);
         }
     }
     if ($instances > 10) {
         $this->_numStrings = $instances;
     }
     $soInstances = range(1, $this->_numStrings, 1);
     $stringOverrideInstances = array();
     if ($this->_soInstance) {
         $soInstances = array($this->_soInstance);
     } elseif (!empty($_POST['old'])) {
         $soInstances = $stringOverrideInstances = array_keys($_POST['old']);
     } elseif (!empty($this->_defaults) && is_array($this->_defaults)) {
         $stringOverrideInstances = array_keys($this->_defaults['new']);
         if (count($this->_defaults['old']) > count($this->_defaults['new'])) {
             $stringOverrideInstances = array_keys($this->_defaults['old']);
         }
     }
     foreach ($soInstances as $instance) {
         $this->addElement('checkbox', "enabled[{$instance}]");
         $this->add('textarea', "old[{$instance}]", NULL, array('rows' => 1, 'cols' => 40));
         $this->add('textarea', "new[{$instance}]", NULL, array('rows' => 1, 'cols' => 40));
         $this->addElement('checkbox', "cb[{$instance}]");
     }
     $this->assign('numStrings', $this->_numStrings);
     if ($this->_soInstance) {
         return;
     }
     $this->assign('stringOverrideInstances', empty($stringOverrideInstances) ? FALSE : $stringOverrideInstances);
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_Admin_Form_WordReplacements', 'formRule'), $this);
 }
Esempio n. 2
0
 /**
  * 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 string
  */
 protected function crm_translate_raw($text, $domain, $count, $plural, $context)
 {
     // gettext domain for extensions
     $domain_changed = FALSE;
     if (!empty($domain) && $this->_phpgettext) {
         if ($this->setGettextDomain($domain)) {
             $domain_changed = TRUE;
         }
     }
     // do all wildcard translations first
     if (!isset(Civi::$statics[__CLASS__]) || !array_key_exists($this->locale, Civi::$statics[__CLASS__])) {
         if (defined('CIVICRM_DSN') && !CRM_Core_Config::isUpgradeMode()) {
             Civi::$statics[__CLASS__][$this->locale] = CRM_Core_BAO_WordReplacement::getLocaleCustomStrings($this->locale);
         } else {
             Civi::$statics[__CLASS__][$this->locale] = array();
         }
     }
     $stringTable = Civi::$statics[__CLASS__][$this->locale];
     $exactMatch = FALSE;
     if (isset($stringTable['enabled']['exactMatch'])) {
         foreach ($stringTable['enabled']['exactMatch'] as $search => $replace) {
             if ($search === $text) {
                 $exactMatch = TRUE;
                 $text = $replace;
                 break;
             }
         }
     }
     if (!$exactMatch && isset($stringTable['enabled']['wildcardMatch'])) {
         $search = array_keys($stringTable['enabled']['wildcardMatch']);
         $replace = array_values($stringTable['enabled']['wildcardMatch']);
         $text = str_replace($search, $replace, $text);
     }
     // dont translate if we've done exactMatch already
     if (!$exactMatch) {
         // use plural if required parameters are set
         if (isset($count) && isset($plural)) {
             if ($this->_phpgettext) {
                 $text = $this->_phpgettext->ngettext($text, $plural, $count);
             } else {
                 // if the locale's not set, we do ngettext work by hand
                 // if $count == 1 then $text = $text, else $text = $plural
                 if ($count != 1) {
                     $text = $plural;
                 }
             }
             // expand %count in translated string to $count
             $text = strtr($text, array('%count' => $count));
             // if not plural, but the locale's set, translate
         } elseif ($this->_phpgettext) {
             if ($context) {
                 $text = $this->_phpgettext->pgettext($context, $text);
             } else {
                 $text = $this->_phpgettext->translate($text);
             }
         }
     }
     if ($domain_changed) {
         $this->setGettextDomain('civicrm');
     }
     return $text;
 }