3 namespace Drupal\locale\Form;
5 use Drupal\Core\Form\ConfigFormBase;
6 use Drupal\Core\Form\FormStateInterface;
9 * Configure locale settings for this site.
13 class LocaleSettingsForm extends ConfigFormBase {
18 public function getFormId() {
19 return 'locale_translate_settings';
25 protected function getEditableConfigNames() {
26 return ['locale.settings'];
32 public function buildForm(array $form, FormStateInterface $form_state) {
33 $config = $this->config('locale.settings');
35 $form['update_interval_days'] = [
37 '#title' => $this->t('Check for updates'),
38 '#default_value' => $config->get('translation.update_interval_days'),
40 '0' => $this->t('Never (manually)'),
41 '7' => $this->t('Weekly'),
42 '30' => $this->t('Monthly'),
44 '#description' => $this->t('Select how frequently you want to check for new interface translations for your currently installed modules and themes. <a href=":url">Check updates now</a>.', [':url' => $this->url('locale.check_translation')]),
47 if ($directory = $config->get('translation.path')) {
48 $description = $this->t('Translation files are stored locally in the %path directory. You can change this directory on the <a href=":url">File system</a> configuration page.', ['%path' => $directory, ':url' => $this->url('system.file_system_settings')]);
51 $description = $this->t('Translation files will not be stored locally. Change the Interface translation directory on the <a href=":url">File system configuration</a> page.', [':url' => $this->url('system.file_system_settings')]);
53 $form['#translation_directory'] = $directory;
54 $form['use_source'] = [
56 '#title' => $this->t('Translation source'),
57 '#default_value' => $config->get('translation.use_source'),
59 LOCALE_TRANSLATION_USE_SOURCE_REMOTE_AND_LOCAL => $this->t('Drupal translation server and local files'),
60 LOCALE_TRANSLATION_USE_SOURCE_LOCAL => $this->t('Local files only'),
62 '#description' => $this->t('The source of translation files for automatic interface translation.') . ' ' . $description,
65 if ($config->get('translation.overwrite_not_customized') == FALSE) {
66 $default = LOCALE_TRANSLATION_OVERWRITE_NONE;
68 elseif ($config->get('translation.overwrite_customized') == TRUE) {
69 $default = LOCALE_TRANSLATION_OVERWRITE_ALL;
72 $default = LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED;
74 $form['overwrite'] = [
76 '#title' => $this->t('Import behavior'),
77 '#default_value' => $default,
79 LOCALE_TRANSLATION_OVERWRITE_NONE => $this->t("Don't overwrite existing translations."),
80 LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED => $this->t('Only overwrite imported translations, customized translations are kept.'),
81 LOCALE_TRANSLATION_OVERWRITE_ALL => $this->t('Overwrite existing translations.'),
83 '#description' => $this->t('How to treat existing translations when automatically updating the interface translations.'),
86 return parent::buildForm($form, $form_state);
92 public function validateForm(array &$form, FormStateInterface $form_state) {
93 parent::validateForm($form, $form_state);
95 if (empty($form['#translation_directory']) && $form_state->getValue('use_source') == LOCALE_TRANSLATION_USE_SOURCE_LOCAL) {
96 $form_state->setErrorByName('use_source', $this->t('You have selected local translation source, but no <a href=":url">Interface translation directory</a> was configured.', [':url' => $this->url('system.file_system_settings')]));
103 public function submitForm(array &$form, FormStateInterface $form_state) {
104 $values = $form_state->getValues();
106 $config = $this->config('locale.settings');
107 $config->set('translation.update_interval_days', $values['update_interval_days'])->save();
108 $config->set('translation.use_source', $values['use_source'])->save();
110 switch ($values['overwrite']) {
111 case LOCALE_TRANSLATION_OVERWRITE_ALL:
113 ->set('translation.overwrite_customized', TRUE)
114 ->set('translation.overwrite_not_customized', TRUE)
118 case LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED:
120 ->set('translation.overwrite_customized', FALSE)
121 ->set('translation.overwrite_not_customized', TRUE)
125 case LOCALE_TRANSLATION_OVERWRITE_NONE:
127 ->set('translation.overwrite_customized', FALSE)
128 ->set('translation.overwrite_not_customized', FALSE)
133 // Invalidate the cached translation status when the configuration setting
134 // of 'use_source' changes.
135 if ($form['use_source']['#default_value'] != $form_state->getValue('use_source')) {
136 locale_translation_clear_status();
139 parent::submitForm($form, $form_state);