diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php index 9726ef8..71abe8a 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php @@ -39,7 +39,6 @@ class LocaleFileImportStatus extends WebTestBase { * The language of the langcode to add. */ function addLanguage($langcode) { - // Add language. $edit = array('predefined_langcode' => $langcode); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); drupal_static_reset('language_list'); @@ -47,10 +46,10 @@ class LocaleFileImportStatus extends WebTestBase { } /** - * Get translations for a array of strings. + * Get translations for an array of strings. * * @param $strings - * A array of strings to translate. + * An array of strings to translate. * @param $langcode * The language code of the language to translate to. */ @@ -132,7 +131,7 @@ class LocaleFileImportStatus extends WebTestBase { ); $this->checkTranslations($strings, $langcode); - // Fill the {locale_file} table with a older file. + // Fill the {locale_file} table with an older file. $file = $this->mockImportedPoFile($langcode, -1); // Add language. @@ -178,4 +177,21 @@ class LocaleFileImportStatus extends WebTestBase { $timestamp = db_query('SELECT timestamp FROM {locale_file} WHERE uri = :uri', array(':uri' => $file->uri))->fetchField(); $this->assertEqual($timestamp, $file->timestamp); } + + /** + * Delete translation files after deleting a language. + */ + function testDeleteLanguage() { + $dir = conf_path() . '/files/translations'; + file_prepare_directory($dir, FILE_CREATE_DIRECTORY); + variable_set('locale_translate_file_directory', $dir); + $langcode = 'de'; + $this->addLanguage($langcode); + $file_uri = $dir. '/po_'. $this->randomString() .'.'. $langcode .'.po'; + file_put_contents($file_uri, $this->randomString()); + $this->assertTrue(is_file($file_uri), 'Translation file is created.'); + language_delete($langcode); + $this->assertTrue($file_uri); + $this->assertFalse(is_file($file_uri), 'Translation file deleted after deleting language'); + } } diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 1844473..f795f99 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -393,18 +393,21 @@ function locale_translate_update_file_history($file) { */ function locale_translate_delete_translation_files($langcode) { $files = locale_translate_get_interface_translation_files($langcode); + $return = TRUE; if (!empty($files)) { foreach ($files as $file) { $success = file_unmanaged_delete($file->uri); if (!$success) { - return FALSE; + $return = FALSE; + } + else { + // Remove the registered translation file if any. + db_delete('locale_file') + ->condition('langcode', $langcode) + ->condition('uri', $file->uri) + ->execute(); } - // Remove the registered translation file if any. - db_delete('locale_file') - ->condition('langcode', $langcode) - ->coddition('uri', $file->uri) - ->execute(); } } - return TRUE; + return $return; }