/**
  * Save options from Preferences page
  *
  * @param array $context
  *
  * @return boolean
  */
 public function dSave(array $context)
 {
     $valid = true;
     $data =& $context['settings']['frontend_localisation'];
     $errors = array();
     if (!$this->meetDependencies(true)) {
         return $valid;
     }
     /* Language codes */
     $old_langs = FLang::getLangs();
     if (!FLang::setLangs($data['langs'])) {
         $valid = false;
         $errors['langs'] = __('Please fill at least one valid language code.');
     }
     $new_langs = FLang::getLangs();
     unset($data['langs']);
     Symphony::Configuration()->set('langs', implode(',', $new_langs), 'frontend_localisation');
     /**
      * When saving Preferences, supplies the old_languages and new_languages arrays.
      *
      * @delegate FLSavePreferences
      * @since    1.4
      *
      * @param string $context   - '/extensions/frontend_localisation/'
      * @param array  $context   - the original context from @delegate Save
      * @param array  $old_langs - old language codes
      * @param array  $new_langs - new language codes
      */
     Symphony::ExtensionManager()->notifyMembers('FLSavePreferences', '/extensions/frontend_localisation/', array('context' => $context, 'old_lang' => $old_langs, 'new_langs' => $new_langs));
     /* Main language */
     if (!FLang::setMainLang($data['main_lang'])) {
         if (!empty($old_langs) || !(isset($new_langs[0]) && FLang::setMainLang($new_langs[0]))) {
             $valid = false;
             $errors['main_lang'] = __('Invalid language code.');
         }
     }
     $main_lang = FLang::getMainLang();
     unset($data['main_lang']);
     Symphony::Configuration()->set('main_lang', $main_lang, 'frontend_localisation');
     Symphony::Configuration()->write();
     if (!empty($errors)) {
         $context['errors']['frontend_localisation'] = $errors;
     }
     return $valid;
 }