3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
14 use Civi\Core\Event\SystemInstallEvent
;
17 * Class LocalizationInitializer
20 class LocalizationInitializer
{
23 * Load the locale settings based on the installation language
25 * @param \Civi\Core\Event\SystemInstallEvent $event
26 * @throws \CRM_Core_Exception
28 public static function initialize(SystemInstallEvent
$event) {
30 // get the current installation language
32 $seedLanguage = $tsLocale;
37 // get the corresponding settings file if any
38 $localeDir = \CRM_Core_I18n
::getResourceDir();
39 $fileName = $localeDir . $seedLanguage . DIRECTORY_SEPARATOR
. 'settings.default.json';
44 if (file_exists($fileName)) {
46 // load the file and parse it
47 $json = file_get_contents($fileName);
48 $settings = json_decode($json, TRUE);
50 if (!empty($settings)) {
51 // get all valid settings
52 $results = civicrm_api3('Setting', 'getfields', []);
53 $validSettings = array_keys($results['values']);
54 // add valid settings to params to send to api
55 foreach ($settings as $setting => $value) {
56 if (in_array($setting, $validSettings)) {
57 $settingsParams[$setting] = $value;
62 // ensure we don't mess with multilingual
63 unset($settingsParams['languageLimit']);
65 // support for enabled languages (option group)
66 if (isset($settings['languagesOption']) && count($settings['languagesOption']) > 0) {
67 \CRM_Core_BAO_OptionGroup
::setActiveValues('languages', $settings['languagesOption']);
70 // set default currency in currencies_enabled (option group)
71 if (isset($settings['defaultCurrency'])) {
72 \CRM_Admin_Form_Setting_Localization
::updateEnabledCurrencies([$settings['defaultCurrency']], $settings['defaultCurrency']);
79 // in any case, enforce the seedLanguage as the default language
80 $settingsParams['lcMessages'] = $seedLanguage;
83 civicrm_api3('Setting', 'create', $settingsParams);