// Note: the file hierarchy for .po must be, for example: l10n/fr_FR/LC_MESSAGES/civicrm.mo
$this->_nativegettext = TRUE;
-
- $locale .= '.utf8';
- putenv("LANG=$locale");
-
- // CRM-11833 Avoid LC_ALL because of LC_NUMERIC and potential DB error.
- setlocale(LC_TIME, $locale);
- setlocale(LC_MESSAGES, $locale);
- setlocale(LC_CTYPE, $locale);
-
- bindtextdomain('civicrm', CRM_Core_I18n::getResourceDir());
- bind_textdomain_codeset('civicrm', 'UTF-8');
- textdomain('civicrm');
-
- $this->_phpgettext = new CRM_Core_I18n_NativeGettext();
- $this->_extensioncache['civicrm'] = 'civicrm';
+ $this->setNativeGettextLocale($locale);
return;
}
// Otherwise, use PHP-gettext
- // we support both the old file hierarchy format and the new:
- // pre-4.5: civicrm/l10n/xx_XX/civicrm.mo
- // post-4.5: civicrm/l10n/xx_XX/LC_MESSAGES/civicrm.mo
- require_once 'PHPgettext/streams.php';
- require_once 'PHPgettext/gettext.php';
-
- $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);
- $this->_extensioncache['civicrm'] = $this->_phpgettext;
+ $this->setPhpGettextLocale($locale);
}
}
return $this->_nativegettext;
}
+
+ protected function setNativeGettextLocale($locale) {
+
+ $locale .= '.utf8';
+ putenv("LANG=$locale");
+
+ // CRM-11833 Avoid LC_ALL because of LC_NUMERIC and potential DB error.
+ setlocale(LC_TIME, $locale);
+ setlocale(LC_MESSAGES, $locale);
+ setlocale(LC_CTYPE, $locale);
+
+ bindtextdomain('civicrm', CRM_Core_I18n::getResourceDir());
+ bind_textdomain_codeset('civicrm', 'UTF-8');
+ textdomain('civicrm');
+
+ $this->_phpgettext = new CRM_Core_I18n_NativeGettext();
+ $this->_extensioncache['civicrm'] = 'civicrm';
+
+ }
+
+ protected function setPhpGettextLocale($locale) {
+
+ // we support both the old file hierarchy format and the new:
+ // pre-4.5: civicrm/l10n/xx_XX/civicrm.mo
+ // post-4.5: civicrm/l10n/xx_XX/LC_MESSAGES/civicrm.mo
+ require_once 'PHPgettext/streams.php';
+ require_once 'PHPgettext/gettext.php';
+
+ $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);
+ $this->_extensioncache['civicrm'] = $this->_phpgettext;
+
+ }
+
+
/**
* Return languages available in this instance of CiviCRM.
*
/**
* Change the processing language without changing the current user language
*
- * @param $language
- * Language (for example 'en_US', or 'fr_CA').
+ * @param $locale
+ * Locale (for example 'en_US', or 'fr_CA').
* True if the domain was changed for an extension.
*/
- public function setLocale($language) {
-
- $config = CRM_Core_Config::singleton();
+ public function setLocale($locale) {
// Change the language of the CMS as well, for URLs.
- CRM_Utils_System::setUFLocale($language);
+ CRM_Utils_System::setUFLocale($locale);
// change the gettext ressources
if ($this->_nativegettext) {
- $locale = $language . '.utf8';
- putenv("LANG=$locale");
-
- setlocale(LC_TIME, $locale);
- setlocale(LC_MESSAGES, $locale);
- setlocale(LC_CTYPE, $locale);
-
- bindtextdomain('civicrm', CRM_Core_I18n::getResourceDir());
- bind_textdomain_codeset('civicrm', 'UTF-8');
- textdomain('civicrm');
-
- $this->_phpgettext = new CRM_Core_I18n_NativeGettext();
- $this->_extensioncache['civicrm'] = 'civicrm';
+ $this->setNativeGettextLocale($locale);
}
else {
// phpgettext
- require_once 'PHPgettext/streams.php';
- require_once 'PHPgettext/gettext.php';
-
- $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);
- $this->_extensioncache['civicrm'] = $this->_phpgettext;
-
+ $this->setPhpGettextLocale($locale);
}
// for sql queries
global $dbLocale;
- $dbLocale = "_{$language}";
+ $dbLocale = "_{$locale}";
}