public function testOptionLanguage() { $this->callAPISuccess('Setting', 'create', array('lcMessages' => 'en_US', 'languageLimit' => array('en_US' => 1))); CRM_Core_I18n_Schema::makeMultilingual('en_US'); global $dbLocale; $dbLocale = '_en_US'; CRM_Core_I18n_Schema::addLocale('fr_CA', 'en_US'); $this->callAPISuccess('Setting', 'create', array('languageLimit' => array('en_US', 'fr_CA'))); // Take a semi-random OptionGroup and test manually changing its label // in one language, while making sure it stays the same in English. $group = $this->callAPISuccess('OptionGroup', 'getsingle', array('name' => 'contact_edit_options')); $english_original = $this->callAPISuccess('OptionValue', 'getsingle', array('option_group_id' => $group['id'], 'name' => 'IM')); $this->callAPISuccess('OptionValue', 'create', array('id' => $english_original['id'], 'name' => 'IM', 'label' => 'Messagerie instantanée', 'option.language' => 'fr_CA')); $french = $this->callAPISuccess('OptionValue', 'getsingle', array('option_group_id' => $group['id'], 'name' => 'IM', 'option.language' => 'fr_CA')); $default = $this->callAPISuccess('OptionValue', 'getsingle', array('option_group_id' => $group['id'], 'name' => 'IM', 'option.language' => 'en_US')); $this->assertEquals($french['label'], 'Messagerie instantanée'); $this->assertEquals($default['label'], $english_original['label']); }
/** * Test creating logging schema when database is in multilingual mode. * Also test altering a multilingual table. */ public function testMultilingualAlterSchemaLogging() { CRM_Core_I18n_Schema::makeMultilingual('en_US'); $logging = new CRM_Logging_Schema(); $logging->enableLogging(); $value = CRM_Core_DAO::singleValueQuery("SELECT id FROM log_civicrm_contact LIMIT 1", array(), FALSE, FALSE); $this->assertNotNull($value, 'Logging not enabled successfully'); $logging->disableLogging(); CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` ADD COLUMN `logging_test` INT DEFAULT NULL", array(), FALSE, NULL, FALSE, TRUE); CRM_Core_I18n_Schema::rebuildMultilingualSchema(array('en_US')); $logging->enableLogging(); $query = CRM_Core_DAO::executeQuery("SHOW CREATE TABLE `log_civicrm_option_value`", array(), TRUE, NULL, FALSE, FALSE); $query->fetch(); $create = explode("\n", $query->Create_Table); CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_value` DROP COLUMN `logging_test`", array(), FALSE, NULL, FALSE, TRUE); $this->assertTrue(in_array(" `logging_test` int(11) DEFAULT NULL", $create)); $logging->disableLogging(); }
public function postProcess() { $values = $this->exportValues(); //cache contact fields retaining localized titles //though we changed localization, so reseting cache. CRM_Core_BAO_Cache::deleteGroup('contact fields'); //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache. CRM_Core_BAO_Cache::deleteGroup('navigation'); // we do this only to initialize monetary decimal point and thousand separator $config = CRM_Core_Config::singleton(); // save enabled currencies and defaul currency in option group 'currencies_enabled' // CRM-1496 if (empty($values['currencyLimit'])) { $values['currencyLimit'] = array($values['defaultCurrency']); } elseif (!in_array($values['defaultCurrency'], $values['currencyLimit'])) { $values['currencyLimit'][] = $values['defaultCurrency']; } // sort so that when we display drop down, weights have right value sort($values['currencyLimit']); // get labels for all the currencies $options = array(); $currencySymbols = self::getCurrencySymbols(); for ($i = 0; $i < count($values['currencyLimit']); $i++) { $options[] = array('label' => $currencySymbols[$values['currencyLimit'][$i]], 'value' => $values['currencyLimit'][$i], 'weight' => $i + 1, 'is_active' => 1, 'is_default' => $values['currencyLimit'][$i] == $values['defaultCurrency']); } $dontCare = NULL; CRM_Core_OptionGroup::createAssoc('currencies_enabled', $options, $dontCare); // unset currencyLimit so we dont store there unset($values['currencyLimit']); // make the site multi-lang if requested if (!empty($values['makeMultilingual'])) { CRM_Core_I18n_Schema::makeMultilingual($values['lcMessages']); $values['languageLimit'][$values['lcMessages']] = 1; // make the site single-lang if requested } elseif (!empty($values['makeSinglelingual'])) { CRM_Core_I18n_Schema::makeSinglelingual($values['lcMessages']); $values['languageLimit'] = ''; } // add a new db locale if the requested language is not yet supported by the db if (!CRM_Utils_Array::value('makeSinglelingual', $values) and CRM_Utils_Array::value('addLanguage', $values)) { $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); if (!substr_count($domain->locales, $values['addLanguage'])) { CRM_Core_I18n_Schema::addLocale($values['addLanguage'], $values['lcMessages']); } $values['languageLimit'][$values['addLanguage']] = 1; } // if we manipulated the language list, return to the localization admin screen $return = (bool) (CRM_Utils_Array::value('makeMultilingual', $values) or CRM_Utils_Array::value('addLanguage', $values)); $filteredValues = $values; unset($filteredValues['makeMultilingual']); unset($filteredValues['makeSinglelingual']); unset($filteredValues['addLanguage']); unset($filteredValues['languageLimit']); Civi::settings()->set('languageLimit', CRM_Utils_Array::value('languageLimit', $values)); // save all the settings parent::commonProcess($filteredValues); if ($return) { CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/localization', 'reset=1')); } }
public function postProcess() { $values = $this->exportValues(); // make the site multi-lang if requested if (CRM_Utils_Array::value('makeMultilingual', $values)) { require_once 'CRM/Core/I18n/Schema.php'; CRM_Core_I18n_Schema::makeMultilingual($values['lcMessages']); $values['languageLimit'][$values['lcMessages']] = 1; // make the site single-lang if requested } elseif (CRM_Utils_Array::value('makeSinglelingual', $values)) { require_once 'CRM/Core/I18n/Schema.php'; CRM_Core_I18n_Schema::makeSinglelingual($values['lcMessages']); } // add a new db locale if the requested language is not yet supported by the db if (!CRM_Utils_Array::value('makeSinglelingual', $values) and CRM_Utils_Array::value('addLanguage', $values)) { require_once 'CRM/Core/DAO/Domain.php'; $domain =& new CRM_Core_DAO_Domain(); $domain->find(true); if (!substr_count($domain->locales, $values['addLanguage'])) { require_once 'CRM/Core/I18n/Schema.php'; CRM_Core_I18n_Schema::addLocale($values['addLanguage'], $values['lcMessages']); } $values['languageLimit'][$values['addLanguage']] = 1; } // if we manipulated the language list, return to the localization admin screen $return = (bool) (CRM_Utils_Array::value('makeMultilingual', $values) or CRM_Utils_Array::value('addLanguage', $values) or CRM_Utils_Array::value('makeSinglelingual', $values)); //cache contact fields retaining localized titles //though we changed localization, so reseting cache. require_once 'CRM/Core/BAO/Cache.php'; CRM_Core_BAO_Cache::deleteGroup('contact fields'); // we do this only to initialize monetary decimal point and thousand separator $config =& CRM_Core_Config::singleton(); if ($monetaryPointSeparator = $config->defaultMonetaryPointSeparator($values['lcMonetary'])) { $values['monetaryDecimalPoint'] = CRM_Utils_Array::value('decimal_point', $monetaryPointSeparator); $values['monetaryThousandSeparator'] = CRM_Utils_Array::value('thousands_sep', $monetaryPointSeparator); } // save all the settings parent::commonProcess($values); if ($return) { CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/localization', 'reset=1')); } }