Merge pull request #13689 from eileenmcnaughton/no_record_payment
[civicrm-core.git] / Civi / Core / LocalizationInitializer.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 namespace Civi\Core;
29
30 use Civi\Core\Event\SystemInstallEvent;
31
32 /**
33 * Class LocalizationInitializer
34 * @package Civi\Core
35 */
36 class LocalizationInitializer {
37
38 /**
39 * Load the locale settings based on the installation language
40 *
41 * @param \Civi\Core\Event\SystemInstallEvent $event
42 * @throws \CRM_Core_Exception
43 */
44 public static function initialize(SystemInstallEvent $event) {
45
46 // get the current installation language
47 global $tsLocale;
48 $seedLanguage = $tsLocale;
49 if (!$seedLanguage) {
50 return;
51 }
52
53 // get the corresponding settings file if any
54 $localeDir = \CRM_Core_I18n::getResourceDir();
55 $fileName = $localeDir . $seedLanguage . DIRECTORY_SEPARATOR . 'settings.default.json';
56
57 // initalization
58 $settingsParams = [];
59
60 if (file_exists($fileName)) {
61
62 // load the file and parse it
63 $json = file_get_contents($fileName);
64 $settings = json_decode($json, TRUE);
65
66 if (!empty($settings)) {
67 // get all valid settings
68 $results = civicrm_api3('Setting', 'getfields', []);
69 $validSettings = array_keys($results['values']);
70 // add valid settings to params to send to api
71 foreach ($settings as $setting => $value) {
72 if (in_array($setting, $validSettings)) {
73 $settingsParams[$setting] = $value;
74 }
75
76 }
77
78 // ensure we don't mess with multilingual
79 unset($settingsParams['languageLimit']);
80
81 // support for enabled languages (option group)
82 if (isset($settings['languagesOption']) && count($settings['languagesOption']) > 0) {
83 \CRM_Core_BAO_OptionGroup::setActiveValues('languages', $settings['languagesOption']);
84 }
85
86 // set default currency in currencies_enabled (option group)
87 if (isset($settings['defaultCurrency'])) {
88 \CRM_Admin_Form_Setting_Localization::updateEnabledCurrencies([$settings['defaultCurrency']], $settings['defaultCurrency']);
89 }
90
91 }
92
93 }
94
95 // in any case, enforce the seedLanguage as the default language
96 $settingsParams['lcMessages'] = $seedLanguage;
97
98 // apply the config
99 civicrm_api3('Setting', 'create', $settingsParams);
100
101 }
102
103 }