* @param $preferred_language
*/
public static function setCommunicationLanguage($communication_language, $preferred_language) {
- $config = CRM_Core_Config::singleton();
- $language = $config->lcMessages;
+ $i18n = CRM_Core_I18n::singleton();
+
+ // FIXME: convert to getLocale when https://issues.civicrm.org/jira/browse/CRM-18362 is fixed
+ global $tsLocale;
+ $currentLocale = $tsLocale;
+ $language = $currentLocale;
// prepare the language for the email
if ($communication_language == CRM_Core_I18n::AUTO) {
// language not in the existing language, use default
$languages = CRM_Core_I18n::languages(TRUE);
- if (!in_array($language, $languages)) {
- $language = $config->lcMessages;
+ if (!array_key_exists($language, $languages)) {
+ $language = $currentLocale;
}
// change the language
- $i18n = CRM_Core_I18n::singleton();
- $i18n->setLanguage($language);
+ $i18n->setLocale($language);
}
/**
setlocale(LC_MESSAGES, $locale);
setlocale(LC_CTYPE, $locale);
- bindtextdomain('civicrm', $config->gettextResourceDir);
+ bindtextdomain('civicrm', CRM_Core_I18n::getResourceDir());
bind_textdomain_codeset('civicrm', 'UTF-8');
textdomain('civicrm');
require_once 'PHPgettext/streams.php';
require_once 'PHPgettext/gettext.php';
- $mo_file = $config->gettextResourceDir . $language . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR . 'civicrm.mo';
+ $mo_file = CRM_Core_I18n::getResourceDir() . $locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR . 'civicrm.mo';
+ if (!file_exists($mo_file)) {
+ // fallback to pre-4.5 mode
+ $mo_file = CRM_Core_I18n::getResourceDir() . $locale . DIRECTORY_SEPARATOR . 'civicrm.mo';
+ }
$streamer = new FileReader($mo_file);
$this->_phpgettext = new gettext_reader($streamer);