/** * Protected constructor to prevent creating a new instance of the * *Singleton* via the `new` operator from outside of this class. */ protected function __construct($locale = null, $databaseConnectorType = CRM_DB_CONNECTOR_TYPE_MYSQL) { // initialize language and user locale if (isset($locale)) { $this->locale = $locale; } else { if (\creamy\DatabaseConnectorFactory::instantiationAvailableForConnectorOfType($databaseConnectorType)) { // else if we have access to database, check the CRM locale setting. $dbConnector = \creamy\DatabaseConnectorFactory::getInstance()->getDatabaseConnectorOfType($databaseConnectorType); $dbConnector->where("setting", CRM_SETTING_LOCALE); if ($settingRow = $dbConnector->getOne(CRM_SETTINGS_TABLE_NAME)) { $this->locale = $settingRow["value"]; } } } // if locale could not be stablished, fallback to default. if (!isset($this->locale)) { $this->locale = CRM_LANGUAGE_DEFAULT_LOCALE; } // initialize map of language texts. $filepath = dirname(dirname(__FILE__)) . CRM_LANGUAGE_BASE_DIR . $this->locale; $translations = $this->getTranslationsFromFile($filepath); if (!isset($translations)) { // fallback to en_US installation (everybody knows english, don't they?) $filepath = dirname(dirname(__FILE__)) . CRM_LANGUAGE_BASE_DIR . "en_US"; $this->locale = "en_US"; $translations = $this->getTranslationsFromFile($filepath); } $this->texts = $translations; }