diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleFileImportStatus.php index 9726ef8..2406b2d 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 = tempnam($dir, "po_") . '.' . $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/lib/Drupal/locale/TranslationsStream.php b/core/modules/locale/lib/Drupal/locale/TranslationsStream.php new file mode 100644 index 0000000..975c184 --- /dev/null +++ b/core/modules/locale/lib/Drupal/locale/TranslationsStream.php @@ -0,0 +1,37 @@ +getTarget()); + return $GLOBALS['base_url'] . '/' . self::getDirectoryPath() . '/' . drupal_encode_path($path); + } +} 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; } diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index ce20b59..2fc097a 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -12,6 +12,7 @@ */ use Drupal\locale\LocaleLookup; +use Drupal\locale\TranslationsStream; /** * Regular expression pattern used to localize JavaScript strings. @@ -170,6 +171,21 @@ function locale_theme() { } /** + * Implements hook_stream_wrappers(). + */ +function locale_stream_wrappers() { + $wrappers = array( + 'translations' => array( + 'name' => t('Translation files'), + 'class' => 'Drupal\locale\TranslationsStream', + 'description' => t('Translation files'), + 'type' => STREAM_WRAPPERS_LOCAL_NORMAL, + ), + ); + return $wrappers; +} + +/** * Implements hook_language_insert(). */ function locale_language_insert($language) {