diff --git a/core/modules/locale/config/schema/locale.schema.yml b/core/modules/locale/config/schema/locale.schema.yml index 72b89e1..e2d1633 100644 --- a/core/modules/locale/config/schema/locale.schema.yml +++ b/core/modules/locale/config/schema/locale.schema.yml @@ -4,6 +4,12 @@ locale.settings: type: mapping label: 'Translate interface settings' mapping: + fallback: + type: sequence + label: 'Fallback language mappings' + sequence: + - type: string + label: 'Language code' cache_strings: type: boolean label: 'Cache strings' diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index c880370..4f67fb7 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -1404,3 +1404,12 @@ function locale_translation_language_table($form_element) { } return $form_element; } + +/** + * Implements hook_language_fallback_candidates_OPERATION_alter(). + */ +function locale_language_fallback_candidates_locale_lookup_alter(array &$candidates, array $context) { + // @todo (in this patch), return proper fallback for this language based on + // settings. + $candidates = array(); +} diff --git a/core/modules/locale/src/Form/LocaleSettingsForm.php b/core/modules/locale/src/Form/LocaleSettingsForm.php index 0157d5e..b1f2070 100644 --- a/core/modules/locale/src/Form/LocaleSettingsForm.php +++ b/core/modules/locale/src/Form/LocaleSettingsForm.php @@ -8,6 +8,7 @@ use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Language\LanguageInterface; /** * Configure locale settings for this site. @@ -27,7 +28,40 @@ public function getFormId() { public function buildForm(array $form, FormStateInterface $form_state) { $config = $this->config('locale.settings'); - $form['update_interval_days'] = array( + $languages = \Drupal::languageManager()->getLanguages(); + if (!empty($languages)) { + $form['fallback'] = array( + '#title' => $this->t('Interface fallbacks'), + '#type' => 'details', + '#open' => TRUE, + '#tree' => TRUE, + ); + + foreach ($languages as $language) { + // Only add options for languages that are different from the current. + $options = array(); + foreach ($languages as $option_language) { + if ($language->getId() != $option_language->getId()) { + $options[$option_language->getId()] = $option_language->name; + } + } + $form['fallback'][$language->getId()] = array( + '#title' => $this->t('Fall back from %language to', array('%language' => $language->name)), + '#type' => 'language_select', + '#options' => $options, + '#default_value' => $config->get('fallback.' . $language->getId()), + '#empty_option' => t('-None-'), + '#empty_value' => '', + ); + } + } + + $form['updates'] = array( + '#type' => 'details', + '#open' => TRUE, + '#title' => $this->t('Translation updates'), + ); + $form['updates']['update_interval_days'] = array( '#type' => 'radios', '#title' => t('Check for updates'), '#default_value' => $config->get('translation.update_interval_days'), @@ -46,7 +80,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $description = t('Translation files will not be stored locally. Change the Interface translation directory on the File system configuration page.', array('@url' => url('admin/config/media/file-system'))); } $form['#translation_directory'] = $directory; - $form['use_source'] = array( + $form['updates']['use_source'] = array( '#type' => 'radios', '#title' => t('Translation source'), '#default_value' => $config->get('translation.use_source'), @@ -66,7 +100,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { else { $default = LOCALE_TRANSLATION_OVERWRITE_NON_CUSTOMIZED; } - $form['overwrite'] = array( + $form['updates']['overwrite'] = array( '#type' => 'radios', '#title' => t('Import behavior'), '#default_value' => $default, @@ -99,6 +133,8 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $values = $form_state->getValues(); $config = $this->config('locale.settings'); + $config->set('fallback', array_filter($values['fallback'])); + $config->set('translation.update_interval_days', $values['update_interval_days'])->save(); $config->set('translation.use_source', $values['use_source'])->save();