From 8ea2301622b317fc0480ebe64d79a7f9fc8e6919 Mon Sep 17 00:00:00 2001 From: Samuel Vanhove Date: Tue, 31 May 2016 17:12:31 -0400 Subject: [PATCH] CRM-16355 - reminders in multilingual sites fix --- CRM/Core/BAO/ActionSchedule.php | 15 +++++++++------ CRM/Core/I18n.php | 8 ++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 09d5998093..f432e5aaf2 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -425,8 +425,12 @@ FROM civicrm_action_schedule cas * @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) { @@ -440,13 +444,12 @@ FROM civicrm_action_schedule cas // 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); } /** diff --git a/CRM/Core/I18n.php b/CRM/Core/I18n.php index 93ceaa510f..f5d55ccc7e 100644 --- a/CRM/Core/I18n.php +++ b/CRM/Core/I18n.php @@ -583,7 +583,7 @@ class CRM_Core_I18n { 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'); @@ -595,7 +595,11 @@ class CRM_Core_I18n { 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); -- 2.25.1