'uiLanguages' => CRM_Core_BAO_Setting::LOCALIZATION_PREFERENCES_NAME,
);
+ public function preProcess() {
+ if (!CRM_Core_I18n::isMultiLingual()) {
+ CRM_Core_Resources::singleton()
+ ->addScriptFile('civicrm', 'templates/CRM/Admin/Form/Setting/Localization.js', 1, 'html-header');
+ }
+ }
+
/**
* Build the form object.
*/
$warningTitle = json_encode(ts("Warning"));
$defaultLocaleOptions = CRM_Admin_Form_Setting_Localization::getDefaultLocaleOptions();
- $domain = new CRM_Core_DAO_Domain();
- $domain->find(TRUE);
-
- if ($domain->locales) {
+ if (CRM_Core_I18n::isMultiLingual()) {
// add language limiter and language adder
$this->addCheckBox('languageLimit', ts('Available Languages'), array_flip($defaultLocaleOptions), NULL, NULL, NULL, NULL, ' ');
$this->addElement('select', 'addLanguage', ts('Add Language'), array_merge(array('' => ts('- select -')), array_diff(CRM_Core_I18n::languages(), $defaultLocaleOptions)));
$values['languageLimit'][$values['addLanguage']] = 1;
}
+ // current language should be in the ui list
+ if (!in_array($values['lcMessages'], $values['uiLanguages'])) {
+ $values['uiLanguages'][] = $values['lcMessages'];
+ }
+
// 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));
$session = CRM_Core_Session::singleton();
- // on multi-lang sites based on request and civicrm_uf_match
- if ($multiLang) {
- $languageLimit = array();
- if (is_array($settings->get('languageLimit'))) {
- $languageLimit = $settings->get('languageLimit');
- }
-
+ $permittedLanguages = CRM_Core_I18n::uiLanguages(TRUE);
+
+ // The locale to be used can come from various places:
+ // - the request (url)
+ // - the session
+ // - civicrm_uf_match
+ // - inherited from the CMS
+ // Only look at this if there is actually a choice of permitted languages
+ if (count($permittedLanguages) >= 2) {
$requestLocale = CRM_Utils_Request::retrieve('lcMessages', 'String');
- if (in_array($requestLocale, array_keys($languageLimit))) {
+ if (in_array($requestLocale, $permittedLanguages)) {
$chosenLocale = $requestLocale;
//CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
// Ed: This doesn't sound good.
- CRM_Core_BAO_Cache::deleteGroup('navigation');
+ // CRM_Core_BAO_Cache::deleteGroup('navigation');
}
else {
$requestLocale = NULL;
if (!$requestLocale) {
$sessionLocale = $session->get('lcMessages');
- if (in_array($sessionLocale, array_keys($languageLimit))) {
+ if (in_array($sessionLocale, $permittedLanguages)) {
$chosenLocale = $sessionLocale;
}
else {
$ufm = new CRM_Core_DAO_UFMatch();
$ufm->contact_id = $session->get('userID');
if ($ufm->find(TRUE) &&
- in_array($ufm->language, array_keys($languageLimit))
+ in_array($ufm->language, $permittedLanguages)
) {
$chosenLocale = $ufm->language;
}
}
}
- ksort($all);
+ asort($all);
}
if ($enabled === NULL) {
return $justEnabled ? $enabled : $all;
}
+ /**
+ * Return the available UI languages
+ * @return array(string languageCode) if $justCodes
+ * array(string languageCode => string languageName) if !$justCodes
+ */
+ public static function uiLanguages($justCodes = FALSE) {
+ // In multilang we only allow the languages that are configured in db
+ // Otherwise, the languages configured in uiLanguages
+ $settings = Civi::settings();
+ if (CRM_Core_I18n::isMultiLingual()) {
+ $codes = array_keys((array) $settings->get('languageLimit'));
+ }
+ else {
+ $codes = $settings->get('uiLanguages');
+ if (!$codes) {
+ $codes = [$settings->get('lcMessages')];
+ }
+ }
+ return $justCodes ? $codes
+ : CRM_Utils_Array::subset(CRM_Core_I18n::languages(), $codes);
+ }
+
/**
* Replace arguments in a string with their values. Arguments are represented by % followed by their number.
*
// CRM-7163 hack: we don’t display langSwitch on upgrades anyway
if (!CRM_Core_Config::isUpgradeMode()) {
- $this->assign('langSwitch', CRM_Core_I18n::languages(TRUE));
+ $this->assign('langSwitch', CRM_Core_I18n::uiLanguages());
}
$this->register_function('crmURL', array('CRM_Utils_System', 'crmURL'));
--- /dev/null
+CRM.$(function($) {
+ $('input[name=inheritLocale]').click(function () {
+ showHideUiLanguages();
+ });
+
+ function showHideUiLanguages() {
+ var val = $('input[name=inheritLocale]:checked').val();
+ if(val == 0) {
+ $('.crm-localization-form-block-uiLanguages').show();
+ } else {
+ $('.crm-localization-form-block-uiLanguages').hide();
+ }
+ }
+
+ showHideUiLanguages();
+});
<td class="label">{$form.inheritLocale.label} {help id='inheritLocale' title=$form.inheritLocale.label}</td>
<td>{$form.inheritLocale.html}</td>
</tr>
+ {if !$form.languageLimit}
<tr class="crm-localization-form-block-uiLanguages">
<td class="label">{$form.uiLanguages.label}</td>
<td>{$form.uiLanguages.html}</td>
</tr>
+ {/if}
<tr class="crm-localization-form-contact_default_language">
<td class="label">{$form.contact_default_language.label}</td>
<td>{$form.contact_default_language.html}<br />
</table>
<h3>{ts}Multiple Languages Support{/ts}</h3>
<table class="form-layout-compressed">
- {if $form.languageLimit}
+ {if $form.makeSinglelingual}
<tr class="crm-localization-form-block-makeSinglelingual_description">
<td></td>
<td><span class="description">{ts 1="http://documentation.civicrm.org"}This is a multilingual installation. It contains certain schema differences compared to regular installations of CiviCRM. Please <a href="%1">refer to the documentation</a> for details.{/ts}</span></td>