Skip to content

Commit

Permalink
Merge pull request #203 from mlutfy/CRM-11755
Browse files Browse the repository at this point in the history
CRM-11755 : support option.language for multi-lingual installations.
  • Loading branch information
kurund committed Mar 20, 2013
2 parents 04ac0d6 + 91cd40e commit d668c0e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions api/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ function civicrm_api($entity, $action, $params, $extra = NULL) {
$transaction = new CRM_Core_Transaction();
}

// support multi-lingual requests
if ($language = CRM_Utils_Array::value('option.language', $params)) {
_civicrm_api_set_locale($language);
}

_civicrm_api3_api_check_permission($apiRequest['entity'], $apiRequest['action'], $apiRequest['params']);

// we do this before we
Expand Down Expand Up @@ -540,3 +545,50 @@ function _civicrm_api_get_entity_name_from_dao($bao){

}


/**
* Sets the tsLocale and dbLocale for multi-lingual sites.
* Some code duplication from CRM/Core/BAO/ConfigSetting.php retrieve()
* to avoid regressions from refactoring.
*/
function _civicrm_api_set_locale($lcMessagesRequest) {
// We must validate whether the locale is valid, otherwise setting a bad
// dbLocale could probably lead to sql-injection.
$domain = new CRM_Core_DAO_Domain();
$domain->id = CRM_Core_Config::domainID();
$domain->find(TRUE);

if ($domain->config_backend) {
$defaults = unserialize($domain->config_backend);

// are we in a multi-language setup?
$multiLang = $domain->locales ? TRUE : FALSE;
$lcMessages = NULL;

// on multi-lang sites based on request and civicrm_uf_match
if ($multiLang) {
$languageLimit = array();
if (array_key_exists('languageLimit', $defaults) && is_array($defaults['languageLimit'])) {
$languageLimit = $defaults['languageLimit'];
}

if (in_array($lcMessagesRequest, array_keys($languageLimit))) {
$lcMessages = $lcMessagesRequest;
}
else {
throw new API_Exception(ts('Language not enabled: %1', array(1 => $lcMessagesRequest)));
}
}

global $dbLocale;

// set suffix for table names - use views if more than one language
if ($lcMessages) {
$dbLocale = $multiLang && $lcMessages ? "_{$lcMessages}" : '';

// FIXME: an ugly hack to fix CRM-4041
global $tsLocale;
$tsLocale = $lcMessages;
}
}
}

0 comments on commit d668c0e

Please sign in to comment.