X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FI18n.php;h=bcb214d66e5e50f6846c9fb922ee001e75bf652b;hb=58a65f77cb2d8381b0128bcdaf30fc33aa802124;hp=f6ed3dcf03396e43a9bdb0950ddf152a89233d23;hpb=59dd77c6fde181e893ef275a12abb991997b60d4;p=civicrm-core.git diff --git a/CRM/Core/I18n.php b/CRM/Core/I18n.php index f6ed3dcf03..bcb214d66e 100644 --- a/CRM/Core/I18n.php +++ b/CRM/Core/I18n.php @@ -126,7 +126,6 @@ class CRM_Core_I18n { * @param string $locale */ protected function setNativeGettextLocale($locale) { - $locale .= '.utf8'; putenv("LANG=$locale"); @@ -141,33 +140,29 @@ class CRM_Core_I18n { $this->_phpgettext = new CRM_Core_I18n_NativeGettext(); $this->_extensioncache['civicrm'] = 'civicrm'; - } /** * Set getText locale. * + * Since CiviCRM 4.5, expected dir structure is civicrm/l10n/xx_XX/LC_MESSAGES/civicrm.mo + * because that is what native gettext expects. Fallback support for the pre-4.5 structure + * was removed in CiviCRM 5.51. + * + * CiviCRM 5.23 added support for the CIVICRM_L10N_BASEDIR constant (and [civicrm.l10n]) + * so that mo files can be stored elsewhere (such as in a web-writable directory, to + * support extensions sur as l10nupdate. + * * @param string $locale */ 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; - } /** @@ -239,6 +234,28 @@ class CRM_Core_I18n { return $justEnabled ? $enabled : $all; } + /** + * Get the options available for format locale. + * + * Note the pseudoconstant can't be used as the key is the name not the value. + * + * @return array + */ + public static function getFormatLocales(): array { + $values = CRM_Core_OptionValue::getValues(['name' => 'languages'], $optionValues, 'label', TRUE); + $return = []; + $return[NULL] = ts('Inherit from language'); + foreach ($values as $value) { + $return[$value['name']] = $value['label']; + } + // Sorry not sorry. + // Hacking in for now since the is probably the most important use-case for + // money formatting in an English speaking non-US locale based on any reasonable + // metric. + $return['en_NZ'] = ts('English (New Zealand)'); + return $return; + } + /** * Return the available UI languages * @return array|string @@ -561,7 +578,7 @@ class CRM_Core_I18n { // phpgettext $mo_file = $path . DIRECTORY_SEPARATOR . 'l10n' . DIRECTORY_SEPARATOR . $this->locale . DIRECTORY_SEPARATOR . 'LC_MESSAGES' . DIRECTORY_SEPARATOR . $domain . '.mo'; $streamer = new FileReader($mo_file); - $this->_extensioncache[$key] = new gettext_reader($streamer); + $this->_extensioncache[$key] = $streamer->length() ? new gettext_reader($streamer) : NULL; } } catch (CRM_Extension_Exception $e) {