Skip to content
Snippets Groups Projects
Commit c4990fc1 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2095787 by Sutharsan, Gábor Hojtsy, fran seva, adci_contributor,...

Issue #2095787 by Sutharsan, Gábor Hojtsy, fran seva, adci_contributor, rpayanm: Configuration translations not updated when manually importing a .po file
parent 35aad826
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -171,6 +171,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) { ...@@ -171,6 +171,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function submitForm(array &$form, FormStateInterface $form_state) { public function submitForm(array &$form, FormStateInterface $form_state) {
\Drupal::moduleHandler()->loadInclude('locale', 'translation.inc');
// Add language, if not yet supported. // Add language, if not yet supported.
$language = $this->languageManager->getLanguage($form_state->getValue('langcode')); $language = $this->languageManager->getLanguage($form_state->getValue('langcode'));
if (empty($language)) { if (empty($language)) {
...@@ -178,16 +179,22 @@ public function submitForm(array &$form, FormStateInterface $form_state) { ...@@ -178,16 +179,22 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$language->save(); $language->save();
drupal_set_message($this->t('The language %language has been created.', array('%language' => $this->t($language->label())))); drupal_set_message($this->t('The language %language has been created.', array('%language' => $this->t($language->label()))));
} }
$options = array( $options = array_merge(_locale_translation_default_update_options(), array(
'langcode' => $form_state->getValue('langcode'), 'langcode' => $form_state->getValue('langcode'),
'overwrite_options' => $form_state->getValue('overwrite_options'), 'overwrite_options' => $form_state->getValue('overwrite_options'),
'customized' => $form_state->getValue('customized') ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED, 'customized' => $form_state->getValue('customized') ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED,
); ));
$this->moduleHandler->loadInclude('locale', 'bulk.inc'); $this->moduleHandler->loadInclude('locale', 'bulk.inc');
$file = locale_translate_file_attach_properties($this->file, $options); $file = locale_translate_file_attach_properties($this->file, $options);
$batch = locale_translate_batch_build(array($file->uri => $file), $options); $batch = locale_translate_batch_build(array($file->uri => $file), $options);
batch_set($batch); batch_set($batch);
// Create or update all configuration translations for this language.
\Drupal::moduleHandler()->loadInclude('locale', 'bulk.inc');
if ($batch = locale_config_batch_update_components($options, array($form_state->getValue('langcode')))) {
batch_set($batch);
}
$form_state->setRedirect('locale.translate_page'); $form_state->setRedirect('locale.translate_page');
} }
} }
...@@ -335,6 +335,22 @@ public function testConfigPoFile() { ...@@ -335,6 +335,22 @@ public function testConfigPoFile() {
} }
} }
/**
* Tests .po file import with user.settings configuration.
*/
public function testConfigtranslationImportingPoFile() {
// Set the language code.
$langcode = 'de';
// Import a .po file to translate.
$this->importPoFile($this->getPoFileWithConfigDe(), array(
'langcode' => $langcode));
// Check that the 'Anonymous' string is translated.
$config = \Drupal::languageManager()->getLanguageConfigOverride($langcode, 'user.settings');
$this->assertEqual($config->get('anonymous'), 'Anonymous German');
}
/** /**
* Helper function: import a standalone .po file in a given language. * Helper function: import a standalone .po file in a given language.
* *
...@@ -592,4 +608,22 @@ public function getPoFileWithConfig() { ...@@ -592,4 +608,22 @@ public function getPoFileWithConfig() {
EOF; EOF;
} }
/**
* Helper function that returns a .po file with configuration translations.
*/
public function getPoFileWithConfigDe() {
return <<< EOF
msgid ""
msgstr ""
"Project-Id-Version: Drupal 8\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
msgid "Anonymous"
msgstr "Anonymous German"
EOF;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment