diff --git a/core/profiles/demo_umami/config/install/language.entity.en.yml b/core/profiles/demo_umami/config/install/language.entity.en.yml new file mode 100644 index 0000000000..7c3305f515 --- /dev/null +++ b/core/profiles/demo_umami/config/install/language.entity.en.yml @@ -0,0 +1,8 @@ +langcode: en +status: true +dependencies: { } +id: en +label: English +direction: ltr +weight: 0 +locked: false diff --git a/core/profiles/demo_umami/config/install/language.entity.es.yml b/core/profiles/demo_umami/config/install/language.entity.es.yml new file mode 100644 index 0000000000..2d9fc7e259 --- /dev/null +++ b/core/profiles/demo_umami/config/install/language.entity.es.yml @@ -0,0 +1,8 @@ +langcode: en +status: true +dependencies: { } +id: es +label: Spanish +direction: ltr +weight: 1 +locked: false diff --git a/core/profiles/demo_umami/config/install/language.entity.und.yml b/core/profiles/demo_umami/config/install/language.entity.und.yml new file mode 100644 index 0000000000..86b51e5802 --- /dev/null +++ b/core/profiles/demo_umami/config/install/language.entity.und.yml @@ -0,0 +1,8 @@ +langcode: en +status: true +dependencies: { } +id: und +label: 'Not specified' +direction: ltr +weight: 2 +locked: true diff --git a/core/profiles/demo_umami/config/install/language.entity.zxx.yml b/core/profiles/demo_umami/config/install/language.entity.zxx.yml new file mode 100644 index 0000000000..8b0c8625f5 --- /dev/null +++ b/core/profiles/demo_umami/config/install/language.entity.zxx.yml @@ -0,0 +1,8 @@ +langcode: en +status: true +dependencies: { } +id: zxx +label: 'Not applicable' +direction: ltr +weight: 3 +locked: true diff --git a/core/profiles/demo_umami/config/install/language.mappings.yml b/core/profiles/demo_umami/config/install/language.mappings.yml new file mode 100644 index 0000000000..3bdb4f1027 --- /dev/null +++ b/core/profiles/demo_umami/config/install/language.mappings.yml @@ -0,0 +1,11 @@ +map: + 'no': nb + pt: pt-pt + zh: zh-hans + zh-tw: zh-hant + zh-hk: zh-hant + zh-mo: zh-hant + zh-cht: zh-hant + zh-cn: zh-hans + zh-sg: zh-hans + zh-chs: zh-hans diff --git a/core/profiles/demo_umami/config/install/language.negotiation.yml b/core/profiles/demo_umami/config/install/language.negotiation.yml new file mode 100644 index 0000000000..eb1724ad6d --- /dev/null +++ b/core/profiles/demo_umami/config/install/language.negotiation.yml @@ -0,0 +1,11 @@ +session: + parameter: language +url: + source: path_prefix + prefixes: + en: en + es: es + domains: + en: '' + es: '' +selected_langcode: site_default diff --git a/core/profiles/demo_umami/config/install/language.types.yml b/core/profiles/demo_umami/config/install/language.types.yml new file mode 100644 index 0000000000..4d48251fdf --- /dev/null +++ b/core/profiles/demo_umami/config/install/language.types.yml @@ -0,0 +1,17 @@ +all: + - language_interface + - language_content + - language_url +configurable: + - language_interface +negotiation: + language_content: + enabled: + language-interface: 0 + language_url: + enabled: + language-url: 0 + language-url-fallback: 1 + language_interface: + enabled: + language-url: 0 diff --git a/core/profiles/demo_umami/config/install/language/en/language.entity.en.yml b/core/profiles/demo_umami/config/install/language/en/language.entity.en.yml new file mode 100644 index 0000000000..16ee5a6fb8 --- /dev/null +++ b/core/profiles/demo_umami/config/install/language/en/language.entity.en.yml @@ -0,0 +1 @@ +label: English diff --git a/core/profiles/demo_umami/config/install/language/en/language.entity.und.yml b/core/profiles/demo_umami/config/install/language/en/language.entity.und.yml new file mode 100644 index 0000000000..86b51e5802 --- /dev/null +++ b/core/profiles/demo_umami/config/install/language/en/language.entity.und.yml @@ -0,0 +1,8 @@ +langcode: en +status: true +dependencies: { } +id: und +label: 'Not specified' +direction: ltr +weight: 2 +locked: true diff --git a/core/profiles/demo_umami/config/install/language/en/language.entity.zxx.yml b/core/profiles/demo_umami/config/install/language/en/language.entity.zxx.yml new file mode 100644 index 0000000000..8b0c8625f5 --- /dev/null +++ b/core/profiles/demo_umami/config/install/language/en/language.entity.zxx.yml @@ -0,0 +1,8 @@ +langcode: en +status: true +dependencies: { } +id: zxx +label: 'Not applicable' +direction: ltr +weight: 3 +locked: true diff --git a/core/profiles/demo_umami/config/install/language/es/language.entity.es.yml b/core/profiles/demo_umami/config/install/language/es/language.entity.es.yml new file mode 100644 index 0000000000..6254aac2ed --- /dev/null +++ b/core/profiles/demo_umami/config/install/language/es/language.entity.es.yml @@ -0,0 +1 @@ +label: EspaƱol diff --git a/core/profiles/demo_umami/config/install/language/es/language.entity.und.yml b/core/profiles/demo_umami/config/install/language/es/language.entity.und.yml new file mode 100644 index 0000000000..ca342824b3 --- /dev/null +++ b/core/profiles/demo_umami/config/install/language/es/language.entity.und.yml @@ -0,0 +1 @@ +label: 'Sin especificar' diff --git a/core/profiles/demo_umami/config/install/language/es/language.entity.zxx.yml b/core/profiles/demo_umami/config/install/language/es/language.entity.zxx.yml new file mode 100644 index 0000000000..b2924ae5e9 --- /dev/null +++ b/core/profiles/demo_umami/config/install/language/es/language.entity.zxx.yml @@ -0,0 +1 @@ +label: 'No aplicable' diff --git a/core/profiles/demo_umami/config/install/locale.settings.yml b/core/profiles/demo_umami/config/install/locale.settings.yml new file mode 100644 index 0000000000..c5eb41986a --- /dev/null +++ b/core/profiles/demo_umami/config/install/locale.settings.yml @@ -0,0 +1,13 @@ +cache_strings: true +translate_english: false +javascript: + directory: languages +translation: + use_source: remote_and_local + default_filename: '%project-%version.%language.po' + default_server_pattern: 'https://ftp.drupal.org/files/translations/%core/%project/%project-%version.%language.po' + overwrite_customized: false + overwrite_not_customized: true + update_interval_days: 0 + path: sites/default/files/translations + import_enabled: true diff --git a/core/profiles/demo_umami/demo_umami.info.yml b/core/profiles/demo_umami/demo_umami.info.yml index 98be81fffe..e96e39443b 100644 --- a/core/profiles/demo_umami/demo_umami.info.yml +++ b/core/profiles/demo_umami/demo_umami.info.yml @@ -42,6 +42,11 @@ install: - responsive_image - content_moderation - workflows + - language + - locale + - config_translation + - content_translation themes: - seven - umami +keep_english: true diff --git a/core/profiles/demo_umami/demo_umami.install b/core/profiles/demo_umami/demo_umami.install index 37025e0826..612b2ccd81 100644 --- a/core/profiles/demo_umami/demo_umami.install +++ b/core/profiles/demo_umami/demo_umami.install @@ -34,6 +34,9 @@ function demo_umami_requirements($phase) { * @see system_install() */ function demo_umami_install() { + // Ensure the translation fields are created in the database. + \Drupal::service('entity.definition_update_manager')->applyUpdates(); + // Assign user 1 the "administrator" role. $user = User::load(1); $user->roles[] = 'administrator'; diff --git a/core/profiles/demo_umami/demo_umami.profile b/core/profiles/demo_umami/demo_umami.profile index 052f5b2672..36849824e7 100644 --- a/core/profiles/demo_umami/demo_umami.profile +++ b/core/profiles/demo_umami/demo_umami.profile @@ -7,6 +7,7 @@ use Drupal\contact\Entity\ContactForm; use Drupal\Core\Form\FormStateInterface; +use Symfony\Component\Yaml\Parser; /** * Implements hook_form_FORM_ID_alter() for install_configure_form(). @@ -18,6 +19,66 @@ function demo_umami_form_install_configure_form_alter(&$form, FormStateInterface $form['#submit'][] = 'demo_umami_form_install_configure_submit'; } +/** + * Implements hook_install_tasks(). + */ +function demo_umami_install_tasks(&$install_state) { + return array( + 'demo_umami_install_import_language_config' => array(), + ); +} + +/** + * Implements hook_install_tasks_alter(). + */ +function demo_umami_install_tasks_alter(&$tasks, $install_state) { + // Moves the language config import task to the end of the install tasks so + // that it is run after the final import of languages. + $task = $tasks['demo_umami_install_import_language_config']; + unset($tasks['demo_umami_install_import_language_config']); + $tasks = array_merge($tasks, array('demo_umami_install_import_language_config' => $task)); +} + +/** + * Imports language configuration overrides. + */ +function demo_umami_install_import_language_config() { + $language_manager = \Drupal::languageManager(); + $yaml_parser = new Parser(); + // The language code of the default locale. + $site_default_langcode = $language_manager->getDefaultLanguage()->getId(); + // The directory where the language config files reside. + $language_config_directory = __DIR__ . '/config/install/language'; + // Sub-directory names (language codes). + // The language code of the default language is excluded. If the user + // chooses to install in Hungarian, French, or Spanish, the language config is + // imported by core and the user has the chance to override it during the + // installation process. + $langcodes = array_diff(scandir($language_config_directory), array('..', '.', $site_default_langcode)); + + foreach ($langcodes as $langcode) { + // All .yml files in the language's config subdirectory. + $config_files = glob("$language_config_directory/$langcode/*.yml"); + + foreach ($config_files as $file_name) { + // Information from the .yml file as an array. + $yaml = $yaml_parser->parse(file_get_contents($file_name)); + // Uses the base name of the .yml file to get the config name. + $config_name = basename($file_name, '.yml'); + // The language configuration object. + $config = $language_manager->getLanguageConfigOverride($langcode, $config_name); + + foreach ($yaml as $config_key => $config_value) { + // Updates the configuration object. + $config->set($config_key, $config_value); + } + + // Saves the configuration. + $config->save(); + } + } +} + /** * Submission handler to sync the contact.form.feedback recipient. */