/** * Enables specified locale. * * @param string $locale Locale code according to RFC 5646. */ function enable_locale($locale) { $db = Database::getInstance(); // Check if the locale exists in the database list($count) = $db->query("SELECT COUNT(*) FROM {locale} WHERE code = :code", array(':code' => $locale), array('return_rows' => Database::RETURN_ONE_ROW, 'fetch_type' => Database::FETCH_NUM)); if ($count == 0) { // The locale does not exist in the database. Create it. Database::getInstance()->query('INSERT INTO {locale} (code, enabled) VALUES(:code, :enabled)', array(':code' => $locale, ':enabled' => 1)); // Import all locale-related info (translations, mail, templates, // formats...) to databse. import_locale_content($locale); } else { // The locale exists in the database. Update it. $db->query("UPDATE {locale} SET enabled = :enabled WHERE code = :code", array(':enabled' => 1, ':code' => $locale)); } }
/** * Import locales content, namely translations, canned messages and mail * templates. * * When the content will be imported the locale will be marked as enabled. * @return boolean True if all content was imported successfully and false * otherwise. */ protected function importLocalesContent() { if (!($db = $this->getDatabase())) { return false; } try { $locales = $db->query('SELECT * FROM {locale} WHERE enabled = :enabled', array(':enabled' => 0), array('return_rows' => Database::RETURN_ALL_ROWS)); foreach ($locales as $locale_info) { $locale = $locale_info['code']; // Import translations, formats, mail templates, ... import_locale_content($locale); // Mark the locale as "enabled" to indicate that all its content // is imported. $db->query('UPDATE {locale} SET enabled = :enabled WHERE code = :locale', array(':locale' => $locale, ':enabled' => 1)); } } catch (\Exception $e) { $this->errors[] = getlocal('Cannot import locales content. Error: {0}', array($e->getMessage())); return false; } return true; }