Commit c4990fc1 authored by alexpott's avatar alexpott

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
......@@ -171,6 +171,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
\Drupal::moduleHandler()->loadInclude('locale', 'translation.inc');
// Add language, if not yet supported.
$language = $this->languageManager->getLanguage($form_state->getValue('langcode'));
if (empty($language)) {
......@@ -178,16 +179,22 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$language->save();
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'),
'overwrite_options' => $form_state->getValue('overwrite_options'),
'customized' => $form_state->getValue('customized') ? LOCALE_CUSTOMIZED : LOCALE_NOT_CUSTOMIZED,
);
));
$this->moduleHandler->loadInclude('locale', 'bulk.inc');
$file = locale_translate_file_attach_properties($this->file, $options);
$batch = locale_translate_batch_build(array($file->uri => $file), $options);
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');
}
}
......@@ -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.
*
......@@ -592,4 +608,22 @@ public function getPoFileWithConfig() {
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;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment